Skip to content
doubtly

2 answers

Best answer

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 units
Enter the three sides of the triangle: 3 4 5
Type: Scalene triangle
Area = 6.00 square units
Enter the three sides of the triangle: 1 2 5
These sides do not form a triangle
Doubtly · 23 Apr 2022 Report
Was this answer helpful?

Answer: read the three sides, check they form a triangle, classify by comparing sides, and find the area with Heron's formula.

#include <stdio.h>
#include <math.h>

int main() {
    float a, b, c, s, area;
    printf("Enter three sides: ");
    scanf("%f %f %f", &a, &b, &c);

    if (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("Equilateral triangle\n");
    else if (a == b || b == c || a == c)
        printf("Isosceles triangle\n");
    else
        printf("Scalene triangle\n");

    s = (a + b + c) / 2;
    area = sqrt(s * (s - a) * (s - b) * (s - c));
    printf("Area = %.2f\n", area);
    return 0;
}

Explanation:

  • Three lengths form a triangle only if the sum of any two sides is greater than the third.
  • All sides equal: equilateral; any two equal: isosceles; all different: scalene.
  • Heron's formula: \(s = \dfrac{a+b+c}{2}\), area \(= \sqrt{s(s-a)(s-b)(s-c)}\).

Sample: sides 3 4 5 give "Scalene triangle" and Area = 6.00. (On Linux, compile with -lm for sqrt.)

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.