Tuesday, 24 December 2013

If the three sides of a triangle are entered through the keyboard, write a program to check whether the triangle is isosceles, equilateral, scalene or right angled triangle.

 #include<iostream>
     using namespace std;

    main()
    {
      float ang1,ang2,ang3;

      cout<<"Enter three angles of a triangle:\n";
      cin>>ang1>>ang2>>ang3;
      if((ang1+ang2+ang3)==180)
      {
       if(ang1==ang2&&ang1==ang3&&ang2==ang3)
         cout<<"\nThe triangle is Equilateral.";
       else if(ang1==ang2||ang1==ang3||ang2==ang3)
         cout<<"\nThe triangle is Isosceles.";
       else if(ang1==90||ang2==90||ang3==90)
         cout<<"\nThe triangle is Right Angled.";
       else if(ang1!=ang2&&ang1!=ang3&&ang2!=ang3)
         cout<<"\nThe triangle is Scalene";
      }
      else
         cout<<"The triangle is not valid";

    }

No comments:

Post a Comment