Program in C to check whether the triangle is valid or not

If three sides of a triangle are entered through the keyboard, write a program to check whether the triangle is valid or not. The triangle is valid if the sum of two sides is greater than or equal to the largest of the three sides.
            If triangle is valid then find that the triangle is isosceles, equilateral, scalene or right angled triangle.

            #include <stdio.h>
            #include <conio.h>
            #include <math.h>
            void main() {
                        float a,b,c, m1,m2,m3;
                        clrscr();
                        printf("Enter the sides of triangle : ");
                        printf("\n\nFirst : "); scanf("%f", &a);
                        printf("Second : "); scanf("%f", &b);
                        printf("Third : "); scanf("%f", &c);
                        m1=a+b;
                        m2=b+c;
                        m3=c+a;
                        if(m1>c && m2>a && m3>b) //Checking that the triangle is valid or not
                        {
                                    if(a==b && b==c) {
                                                printf("\nEquilateral Triangle");
                                    } else if (a==b || b==c || c==a) {
                                                printf("\nIsoceles Triangle");
                                                m1=sqrt(a*a+b*b);
                                                m2=sqrt(b*b+c*c);
                                                m3=sqrt(c*c+a*a);
                                                if(m1==c ||  m2==a || m3==b) {
                                                            printf("\nRight Angled Triangle");
                                                }
                                    } else {

                                                printf("\nScalene Triangle");
                                                m1=sqrt(a*a+b*b);
                                                m2=sqrt(b*b+c*c);
                                                m3=sqrt(c*c+a*a);
                                                if(m1==c || m2==a || m3==b) {
                                                            printf("\nRight Angled Triangle");
                                                }          
                                    }
                        }          
                        getch();
            }


Post a Comment