Programming Examples
Cpp program to check entered three sides can form triangle.
Write a cpp program to input three sides of a triangle and check whether it can form a triangle or not.
The sum of two sides of a triangle should be greater than the third side .
#include
using namespace std;
int main()
{
float a,b,c;
cout<<"Enter three sides ";
cin>>a>>b>>c;
if((a+b)>c && (b+c)>a && (a+c)>b)
{
cout<<"It can form a triangle";
}
else
{
cout<<"It cannot form a triangle";
}
return 0;
}
Output
Enter three sides
13.5
10.2
23.6
It can form a triangle
------------------------------
Enter three sides
2
5
7
It cannot form a triangle