Write a program that calculates and displays the area of a triangle whose lengths must be entered on all three sides. Use the formula:
$$S^2 = P*(P-A)*(P-B)*(P-C)$$
where A, B, C are the lengths of the three sides (type int) and P the half-perimeter of the triangle.
Difficulty level

Video recording
This exercise is mostly suitable for students
#include <stdio.h>
#include <math.h>
int main()
{
int A, B, C;
double P;
printf("Enter the 3 sides of a triangle: ");
scanf("%d %d %d", &A,&B,&C);
P=((double)A+B+C)/2;
printf("Area = %f\n", sqrt(P*(P-A)*(P-B)*(P-C)) );
return 0;
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
