Answer: Check the triangle inequality, classify by comparing sides (equilateral/isosceles/scalene) and find area with Heron's formula.
Logic:
- Valid triangle only if each side is positive and the sum of any two sides is greater than the third.
- All three sides equal: equilateral; any two equal: isosceles; all different: scalene.
- Area by Heron's formula: \( s = \frac{a+b+c}{2} \), \( A = \sqrt{s(s-a)(s-b)(s-c)} \).
Program:
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c, s, area;
printf("Enter the three sides of the triangle: ");
scanf("%f %f %f", &a, &b, &c);
/* Validity: sum of any two sides must be greater than the third */
if (a <= 0 || b <= 0 || c <= 0 || a + b <= c || b + c <= a || a + c <= b)
{
printf("These sides do not form a triangle\n");
return 0;
}
if (a == b && b == c)
printf("Type: Equilateral triangle\n");
else if (a == b || b == c || a == c)
printf("Type: Isosceles triangle\n");
else
printf("Type: Scalene triangle\n");
/* Area by Heron's formula */
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("Area = %.2f square units\n", area);
return 0;
}Sample output (actual run):
Enter the three sides of the triangle: 5 5 5
Type: Equilateral triangle
Area = 10.83 square unitsEnter the three sides of the triangle: 3 4 5
Type: Scalene triangle
Area = 6.00 square unitsEnter the three sides of the triangle: 1 2 5
These sides do not form a triangle