C++ program to check whether a triangle is valid or not














































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. 

NoteA 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; 

  int main() { 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"; } return 0; }

Output:

Enter first angle
20
Enter second angle
40
Enter third angle
120

It is a valid triangle.


Comments