#include <stdio.h>
#include <math.h>
int main() {
double side1, side2, side3, s, area;
// Input the lengths of the sides
printf("Enter length of side 1: ");
scanf("%lf", &side1);
printf("Enter length of side 2: ");
scanf("%lf", &side2);
printf("Enter length of side 3: ");
scanf("%lf", &side3);
// Calculate semi-perimeter
s = (side1 + side2 + side3) / 2;
// Calculate area using Heron's formula
area = sqrt(s * (s - side1) * (s - side2) * (s - side3));
// Check if the sides can form a triangle
if (area > 0) {
printf("Area of the triangle = %.2f\n", area);
} else {
printf("Invalid sides! The given lengths do not form a triangle.\n");
}
return 0;
}
Comments
Post a Comment