main()
{
int a,b,c;
printf("Enter the sides of a triangle :- ");
scanf("%d%d%d",&a,&b,&c);
if((a>b && a>c) && a<(b+c) || (b>a && b>c) && b<(a+c) || (c>a && c>b) && c<(a+b) || (a==b && b==c))
{
if(a==b && b==c)
printf("This triangle is an equilateral triangle.");
if(a==b || b==c || a==c)
printf("This triangle is an isosceles triangle. ");
if(a!=b && b!=c && a!=c)
printf("This triangle is a scalene triangle. ");
if(a>b && a>c)
{
if(a*a==(b*b)+(c*c))
printf("This triangle is a right angled triangle. ");
}
else if(b>a && b>c)
{
if(b*b==(a*a)+(c*c))
printf("This triangle is a right angled triangle. ");
}
else
{
if(c*c==(a*a)+(b*b))
printf("This triangle is a right angled triangle. ");
}
}
else
printf("These are the sides of a invalid triangle.");
}
output:-
on a=3
ReplyDeleteb=3
c=3
out put is wronge
if(a==b && b==c)
ReplyDeleteprintf("This triangle is an equilateral triangle.");
never be true in your code
Sorry!! its my mistake and thanks to remind me about my mistake .....
DeleteI m going to make it right ....
but if we give input as 5,4,3 it will take it as scalene triangle..then how i will get right angled triangle...
ReplyDeletePlz, compile it on your TurboC compiler. It will definitely give the right result. Because, triangle with sides 5,4,3 is both scalene and right angled triangle and this program tells this in this code.
DeleteTRY This, it'll never fail... no matter if you enter +ve, -ve or even 0 values.
ReplyDeletehere's the code i have written-
# include
int main()
{
float a,b,c,s;
printf("enter the sides of the triangle\n");
scanf("%f%f%f",&a,&b,&c);
if((a!=0&&a>0)&&(b!=0&&b>0)&&(c!=0&&c>0))
{
if(a>b&&a>c)
{
s=b+c;
if(s>a)
{
if(b==c)
{
if(b*b+c*c==a*a)
printf("right angeled & isosceles tri");
else
printf("isosceles tri");
}
else if(b!=c)
{
if(b*b+c*c==a*a)
printf("right angeled & scelene tri");
else
printf("scelene tri");
}
}
else
printf("invalid tri");
}
else if(b>a&&b>c)
{
s=a+c;
if(s>b)
{
if(a==c)
{
if(a*a+c*c==b*b)
printf("right angeled & isosceles tri");
else
printf("isosceles tri");
}
else if(a!=c)
{
if(a*a+c*c==b*b)
printf("right angeled & scelene tri");
else
printf("scelene tri");
}
}
else
printf("invalid tri");
}
else if(c>a&&c>b)
{
s=a+b;
if(s>c)
{
if(a==b)
{
if(a*a+b*b==c*c)
printf("right angeled & isosceles tri");
else
printf("isosceles tri");
}
else if(a!=b)
{
if(a*a+b*b==c*c)
printf("right angeled & scelene tri");
else
printf("scelene tri");
}
}
else
printf("invalid tri");
}
else if((a==b)&&(a==c)&&(b==c))
printf("equilateral tri");
else if((a>b&&a==c)||(b>c&&b==a)||(c>a&&c==b))
printf("isosceles tri");
else
printf("invalid tri");
}
else
printf("tri doesn't exist");
return 0;
}
try with any random combination of a,b and c
i hope this helps
on putting 3 values 5,5,5, the output is : This triangle is an equilateral triangle.This triangle is an isosceles triangle.
ReplyDeletei saw the code, the logic is correct but why on putting 3 same values it is saying This triangle is an equilateral triangle.This triangle is an isosceles triangle. i can't understand
ReplyDelete