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:
#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
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: