C program to check whether triangle is valid or not if angles are given; Through this tutorial, we will learn how to check whether triangle is valid or not if angles are given in c programs.
Programs and Algorithm to Check Triangle is Valid or Not using Angles
- Algorithm to Check Triangle is Valid or Not using Angles
- C Program to Check Triangle is Valid or Not using Angles
Algorithm to Check Triangle is Valid or Not using Angles
Use the following algorithm to write a program to find the third angle of a triangle if two angles are given; as follows:
- Take input angles of triangle from user and store it in some variables.
- Compute sum of all three angles, store sum in some variables.
- Check
if(sum == 180)then, triangle can be formed otherwise not.
C Program to Check Triangle is Valid or Not using Angles
/* C Program to Check Triangle is Valid or Not using Angles */
#include<stdio.h>
int main()
{
int angle1, angle2, angle3, Sum;
printf("\n Please Enter Three Angles of a Triangle : ");
scanf("%d%d%d", &angle1, &angle2, &angle3);
Sum = angle1 + angle2 + angle3;
if(Sum == 180)
{
printf("\n This is a Valid Triangle");
}
else
{
printf("\n This is an Invalid Triangle");
}
return 0;
}
The output of the above c program; as follows:
Please Enter Three Angles of a Triangle : 90 45 45 This is a Valid Triangle