Question : if three sides of a triangle are entered through the keyboard, write a program to check whether the triangle is valid or not. the triangle is valid if the sum of two sides is greater than the largest of three sides.
source code
#include <iostream>
#include<conio.h>
int greternum(int ,int,int);
int sumofsmaller(int ,int ,int,int );
using namespace std;
int main()
{
int a,b,c,grater,smaller;
cout<<"Enter 3 number : ";
cin>>a>>b>>c;
grater=greternum(a,b,c);
smaller=sumofsmaller(a,b,c,grater);
//cout<<grater <<endl<<smaller <<endl;
if (smaller > grater)
{
cout<<"it is valid triangle ";
}
else
{
cout<<"it is not valid triangle ";
}
getch();
return 0;
}
int sumofsmaller(int a, int b,int c,int grater)
{
if (a<grater && b<grater)
{
return a+b;
}
else if (a<grater && c<grater )
{
return a+c;
}
else
{
return c+b;
}
}
int greternum(int num1,int num2,int num3)
{
if (num1<num2 && num3<num2)
{
return num2;
}
else if (num1<num3 && num2<num3 )
{
return num3;
}
else
{
return num1;
}
}
No comments:
Post a Comment