This C Program calculates the area of a triangle given it’s three sides. The formula or algorithm used is: Area = sqrt(s(s – a)(s – b)(s – c)), where s = (a + b + c) / 2 or perimeter / 2. and a, b & c are the sides of triangle.
Here is source code of the C program to calculate the area of a triangle. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C program to find the area of a triangle, given three sides
int s, a, b, c, area;
printf("Enter the values of a, b and c \n");
scanf("%d %d %d", &a, &b, &c);
/* compute s */
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("Area of a triangle = %d \n", area);
$ cc pgm1.c -lm $ a.out Enter the values of a, b and c 12 10 8 Area of a triangle = 39
Sanfoundry Global Education & Learning Series – 1000 C Programs.