C++ program to check whether a triangle is valid or not
Problem statement:
Write a program to check whether a triangle is valid or not, when the three angles of the triangle are the inputs.
Note : A triangle is valid if the sum of all the three angles is equal to 180 degrees.
C++ Program to check whether a triangle is valid triangle or not.
#include<bits/stdc++.h>
using namespace std;
intmain(){
int a , b , c; //to accept 3 angles from the user;cout<<"Enter first angle \n";
cin>>a;
cout<<"Enter second angle \n";
cin>>b;
cout<<"Enter third angle \n";
cin>>c;
if( a + b + c == 180 && a!=0 && b!=0 && c!=0)
{
cout<<"It is a valid triangle. \n";
}
else
{
cout<<"It is not a valid triangle\n";
}
return0;
}
Comments