Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered through the keyboard. A triangle is valid if the sum of all the three angles is equal to 180 degrees.
void main()
{
while (1)
{
float a,b,c;
int s;
printf("\nInput the number of sides the figure has");
scanf("%d",&s);
if(s==3)
printf("\nThe figure is 3 sided");
else
{
printf("\nThe figure is not 3 sided");
break;
}
printf("\nInput the three angles of the triangle");
scanf("%f%f%f",&a,&b,&c);
if(a+b+c==180)
printf("\nThe figure is a triangle");
else
printf("\nThe figure is not a triangle");
break;
}
}
Subscribe to:
Post Comments (Atom)
thanxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxchomu!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ReplyDelete/*This code 100% works without errors and easy logic*/
ReplyDelete#include
#include
main()
{
int d1,d2,d3;
cout<<"enter the three degrees:"<>d1>>d2>>d3;
if(d1+d2+d3==180)
cout<<"the triangle is valid:"<<endl;
else
cout<<"the triangle is not valid:"<<endl;
system("pause");
return 0;
}
/* aforesaid solutions r correct...but there r some other conditions for a valid triangle */
ReplyDeleteinclude
void main()
{
int x,y,z;
printf("Input the angles of the triangle(in degree): \n");
scanf("%d %d %d", &x, &y, &z);
if(x+y+z==180)
{
if((x+y)>=z)
printf("The triangle is valid\n");
else
{
if((x+z)>=y)
printf("The triangle is valid\n");
else
{
if((y+z)>=x)
printf("The triangle is valid\n");
else
{
if(x==y==z)
printf("The triangle is valid\n");
}
}
}
}
else
printf("The triangle is invalid\n");
}