Write a C program to input all sides of a triangle and check
Write a C++ program to input all sides of a triangle and check whether these sides represent a triangle that is valid or not valid. A triangle is valid if and only if sum of any two sides is > the third side. Suppose a. b, c are the three sides of a triangle, then the triangle can valid only if the following three conditions are all time: a + b Greater-Than c b + c Greater-Than a a + c Greater-Than b
Solution
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cout << \"Input the first side of triangle : \";
cin >> a;
cout << \"Input the second side of triangle : \";
cin >> b;
cout << \"Input the third side of triangle : \";
cin >> c;
if((a+b)>c && (b+c)>a && (c+a)>b)
cout << \"It\'s a valid triangle.\";
else
cout << \"It\'s invalid triangle.\";
return 0;
}
OUTPUT:
Input the first side of triangle : 5
Input the second side of triangle : 3
Input the third side of triangle : 8
It\'s invalid triangle.
