C program to enter the base and height of a triangle and find its area
ADVERTISEMENTS
C program to enter the base and height of a triangle and find its area.
There are you will learn how to find the area of a triangle by using the base & height of the triangle in C language.
Formula:
a = (b + h) / 2
Where:
a = area
b = base
h = height
Let us understand this example through the C program:
// C program to find the area of a triangle if base and height are given
#include <stdio.h>
int main() {
float b, h, a;
// b = base
// h = height
// a = area
printf("Enter the base & height of the triangle::\n");
scanf("%f%f", &b, &h);
// Calculate area of the triangle
a = (float)((b * h) / 2);
// Output
printf("\nArea of the triangle = %f sq. units", a);
return 0;
}
Output:
Enter the base & height of the triangle::
5
7
Area of the triangle = 17.500000 sq. units