logo image

C Language program to calculate triangle area

Views: 17

Following program shows you how to calculate triangle area. This program gets triangle base and height from user and calculates area and prints it using following formula Area = base X height / 2

#include <stdio.h>

int main() {
	float triangleBase;
	float triangleHeight;

	printf("Enter the base of triangle:");
	scanf("%f", &triangleBase);

	printf("Enter the height of triangle:");
	scanf("%f", &triangleHeight);

	float areaOfTriangle = (triangleBase * triangleHeight) / 2;
	printf("Area of triangle is: %f", areaOfTriangle);


Enter the base of triangle: 45
Enter the height of triangle: 20
Area of triangle is: 450.000000