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