#include <stdio.h>
int main(void)
    int a,b,c;
    printf("Enter the sides of the triangle");
    if(a+b<c || b+c<a || c+a<b)
    printf("cant form a triangle");
    else if(a==b==c)
    printf("eq triangle");
    else if(a!=b && b!=c && c!=a)
    printf("sca triangle");
    else if(a==b&&b!=c || a!=b&&b==c)
    printf("Iso triangle");

am starting to code.. i have coded this and am not getting the eq triangle working .. can u plz guide me whats wrong in it?

8 Years
Discussion Span
Last Post by NP-complete
printf("Enter the sides of the triangle");

do this three times. side a, side b, side c


Or some thing of this sort

int main()
    int a,b,c;
    printf("A is %d\nB is %d\nC is %d\n",a,b,c);
    return 1;

PS: Using scanf is a bad idea. The sooner you shift to fgets the better


IMHO you must change line no. 9 to something like:

else if (a==b && b==c && c==a)

The advise that finito gave you can be considered but that's not the concern in this case. Your logical checking is not right.

Actually your version will only work if you input all sides as 1.


Because in C a 1 also means TRUE. And in that "if" if a=1,b=1 and c=1 what it does is it first checks whether a == b i.e whether true == true....that's TRUE so next it checks whether true == c OR whether true == 1 OR whether true == true (since 1 means true), and obviously true == true is indeed TRUE. So your code will only print "eq triangle" if you enter 1 for all three sides.

Hope that clarifies.

P.S: @ abhimanipal:

In my opinion, scanf() is not that bad for simple inputs of ints, chars or floats. It only gets a bit buggy when it comes to strings. Then fgets() can surely be a big help (and is also safe). Otherwise for simple usage I think scanf() is just fine. But yes, there are hidden gotchas and fgets() is definitely better.
But it all depends on the coder how he uses the functions given to him.

Edited by NP-complete: n/a

Votes + Comments
It all depends how the function is used. Correct!
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.