// Write a c program to calcuate the area of triangle.
#include <stdio.h>
int main() {
int Height, Base;
float areaOfTriangle;
printf("Enter the Height and Base of Triangle : ");
scanf("%d %d", &Height, &Base);
areaOfTriangle = 0.5 * Height * Base;
printf("Area of Triangle : %f", areaOfTriangle);
return 0;
}
- The program starts with by including the standard input/output stdio.h header file.
- The main() function defined.
- Three variables are declared: Height and Base are both integer data type, areaOfTriangle is the float data type.
- A prompt message display on the user screen using the printf() function, for asking the user enter the Height and Base of the triangle.
- The scanf() function is used to read/takes the value from the user, for Height and Base variable and given value stored in Height and Base variable respectively.
- The area of triangle is calculated using the formula (0.5* Height * Base) and store the calculated value in the areaOfTriangle variable.
- Finally, the result(Area of Triangle) is displayed on the user screen using the printf() function with the help of format specifier %f to print the float value of the calculated area of triangle.
- The return statement is used to exit the program successfully.
Comments
Oops!