Programming Examples

Cpp program to input 3 sides of a triangle and print whether it is an equilateral scalene or isosceles triangle


Write a cpp program to input three sides of a triangle and print whether it is an equilateral scalene or isosceles triangle

Solution

#include<iostream>
using namespace std;
int main()
{
     float a,b,c;
     cout<<"Enter three sides of triangle";
     cin>>a>>b>>c;
     if(a+b>c || b+c>a ||a+c>b)
     {
          if(a==b && b==c & c==a)
          {
               cout<<"Equilateral triangle";
          }
          else if(a==b || b==c || c==a)
          {
               cout<<"Isosceles triangle";
          }
          else
          {
               cout<<"Scalene triangle";
          }
     }
     else
     {
          cout<<"Entered sides cannot form a triangle";
     }
     return 0;
}
Output

Enter three sides of triangle

10

10

25

Entered sides cannot form a triangle

-----------------------------------------------

Enter three sides of triangle

10

10

23

Isosceles triangle


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz