Source code:
//Write a C program to check whether a triangle can be formed by the given value for the angles
#include <stdio.h>
int main()
{
int anga, angb, angc, sum, flag;
printf("Enter three angles:");
scanf("%d %d %d", &anga, &angb, &angc);
/* Calculate the sum of all angles of triangle */
sum = anga + angb + angc;
/* Check whether sum=180 then its a valid triangle otherwise not */
if(sum == 180)
flag = 1;
else
flag = 0;
if (flag == 1)
{
printf("The triangle is valid.");
}
else
{
printf("The triangle is not valid.");
}
return 0;
}
Or, Source code:
#include <stdio.h>
int main()
{
int anga, angb, angc, sum;
printf("Enter three angles:");
scanf("%d %d %d", &anga, &angb, &angc);
sum = anga + angb + angc;
if(sum == 180)
printf("The triangle is valid.");
else
printf("The triangle is not valid.");
return 0;
}
Output:
No comments:
Post a Comment