Home » CPP Programming Examples For Practice » CPP Programs » Write a C++ program to check whether a triangle is valid or not, when the three angles of the triangle are entered by the user. A triangle is valid if the sum of all the three angles is equal to 180 degrees
#include<iostream>usingnamespacestd;intmain(){intangle1,angle2,angle3;cout<<"Enter the three angles of triangle:";cin>>angle1>>angle2>>angle3;if(angle1+angle2+angle3==180)cout<<"Triangle is valid";elsecout<<"Triangle is not valid";return0;}
The Output Is:
SAMPLE RUN # 1
Enter the three angles of triangle:60 50 50
Triangle is not valid
SAMPLE RUN # 2
Enter the three angles of triangle:60 90 30
Triangle is valid
Post a Comment