Solved programming problem

Check whether it is a valid triangle or not in C.

Source code

#include <stdio.h>

int main()

{

    float a;

    float b;

    float c;

    printf("Please enter three value: ");

    scanf("%f %f %f",&a,&b,&c);

    if ((a + b <= c) || (a + c <= b) || (b + c <= a))

     {

        printf("It is not a valid triangle
");

     }

    else if ((a==b) && (b==c) && (a==c))

        {

           printf("It is a valid and equilateral triangle
");

        }

    else if ((a==b) || (b==c))

        {

           printf("It is a valid and isosceles triangle
");

        }

    else if ((a!=b) && (b!=c) && (a!=c))

        {

            printf("It is a valid and scalene triangle
");

        }

    else

        {

        printf("It is not a valid triangle
");

        }

    return 0;

}

Output

Please enter three value: 3 3 3

It is a valid and equilateral triangle.

Join the discussion

Add your comment