C++ Function to test for a valid triangle.

//C++ Function to test for a valid triangle.


#include <iostream>
using namespace std;
int IsTriangle(int a,int b,int c);
int main() 
{
	int a,b,c,find;
	cout << "Enter 3 side of triangle A B C : \n";
	cin >> a;
	cin >> b;
	cin >> c;
	find=IsTriangle(a,b,c);
	if(find==1)
		cout << "\nValid triangle ";
	else
		cout << "\nInvalid triangle ";
        return 0;
}
int IsTriangle(int a,int b,int c)
{
	int chk;
	if(a+b>c && a+c>b && b+c>a)
		chk=1;
	else
		chk=0;
	return chk;
}

Output :
Enter 3 side of triangle A B C :
5
6
6

Valid triangle



Leave a comment