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


Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 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 Best Website and Software Company in Allahabad