Input
Enter sides of the triangle: 5 7 3
Output
Triangle is valid
Input
Enter sides of the triangle: 6 3 2
Output
Triangle is invalid
Step 1: START
Step 2: Enter the sides of the triangle.
Step 3: Check the condition:
if (some of any two sides is greater than 3rd sides)
print triangle is valid
else
print triangle is invalid
Step 4: END
/* Check triangle is valid or not */
#include <stdio.h>
int main()
{
int a,b,c;
printf(" Enter three sides of a triangle : ");
scanf("%d%d%d",&a,&b,&c);
if(a+b>c)
if(b+c>a)
if(a+c>b)
printf("Triangle is valid ");
else
printf("Triangle is not valid ");
else
printf("Triangle is not valid ");
else
printf("Triangle is not valid ");
return 0;
}
/* Check Triangle is valid or not */
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<" Enter three sides of a triangle : ";
cin>>a>>b>>c;
if(a+b>c)
if(b+c>a)
if(a+c>b)
cout<<"Triangle is valid ";
else
cout<<"Triangle is not valid ";
else
cout<<"Triangle is not valid ";
else
cout<<"Triangle is not valid ";
return 0;
}
Enter sides of the triangle: 6 3 2
Triangle is invalid
advertisment