14. Write a c program to input angles of a triangle and check whether triangle is valid or not.
Answers
Answered by
1
Answer:
Explanation:
Evaluate 2 conditions :-
1) Sum of all angles should be 180 degress.
2) None of angles should be 0 degress.
#include <stdio.h>
int main()
{
int angleA, angleB, angleC, sum;
/* Take the input of 3 angles of triangle */
printf("Enter 3 angles in degrees : ");
scanf("%d%d%d", &angleA, &angleB, &angleC);
sum = angleA + angleB + angleC;
if(angleA != 0 && angleB != 0 && angleC != 0 && sum == 180)
{
printf("Triangle is valid with angles provided.");
}
else
{
printf("Triangle is not valid with angles provided.");
}
return 0;
}
Answered by
0
Find sum of all three angles, store sum in some variable say sum = angle1 + angle2 + angle3 . Check if(sum == 180) then, triangle can be formed otherwise not. In addition, make sure angles are greater than 0 i.e. check condition for angles if(angle1 > 0 && angle2 > 0 && angle3 > 0) .
Similar questions
Social Sciences,
5 months ago
Computer Science,
11 months ago
CBSE BOARD X,
11 months ago
History,
1 year ago
Math,
1 year ago