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.
Program Code:
Program Code:
#include<iostream>
using namespace std;
int main()
{
int first_angle;
int second_angle;
int third_angle;
cout<<"Enter the first angle of triangle:";
cin>>first_angle;
cout<<endl;
cout<<"Enter the second angle of triangle:";
cin>>second_angle;
cout<<endl;
cout<<"Enter the third angle of triangle:";
cin>>third_angle;
cout<<endl;
if (first_angle + second_angle + third_angle == 180)
{
cout<<"Triangle is valid";
}
else
{
cout<<"Triangle is not valid";
}
return 0;
}
The program output is tested on www.jdoodle.com
Output:
Enter the first angle of triangle: 120
Enter the second angle of triangle: 40
Enter the third angle of triangle: 20
Triangle is valid
Thanks
Mukesh Rajput
Post A Comment:
0 comments: