Turbo C | Weird and amazing

Status
Not open for further replies.

prateek

Banned
Banned
266
2009
72
0
Why the output of the following program comes False

PHP:
#include<stdio.h>
void main()
{
int a=15, b=10, c=5;
if(a>b>c)
printf("True");
else
printf("False");
}


plzz tell me ... help needed
 
13 comments
Why the output of the following program comes False

PHP:
#include<stdio.h>
void main()
{
int a=15, b=10, c=5;
if(a>b>c)
printf("True");
else
printf("False");
}


plzz tell me ... help needed


because in below statement,the compiler(parser) see...
a>b>c as ((a>b)>c)
so ,if a=15,b=10,c=5
a>b ==> true (returns 1)
now 1 > 5 (c) ==> false

Therefore , compiler returns false .The concept of left associativity .
 
the whole concept of your program is wrong, how can you compare values without getting an input from an user and claim it as true or false ? :facepalm:
If you get an input from an user, and ask for "true or false", that has some sense. If you get my point and agree with what i say, then this must be the program :

Code:
#include<stdio.h> 
void main() 
{ 
int a,b,c; 
scanf(%d %d %d, &a, &b, &c);
if(a>b&&a>c)
printf("True"); 
else 
printf("False"); 
}

If its "greatest of 3 numbers, then the program would be :

Code:
#include<stdio.h> 
void main() 
{ 
int a,b,c; 
scanf(%d %d %d, &a, &b, &c);
if(a>b&&a>c)
printf("A is Big"); 
else 
if(b>c)
printf("B is Big"); 
else
printf("C is Big");
}

any doubts ? feel free to reply :)
 
Froomple

actually my exam is next week
i got some previous year questions and tried to solve them
and found this question

the question was what was the output of the program ..


thanks to all of you epecially Techking
rep added for all :)


edit
techking
i can't give rep to u
You must spread some Reputation around before giving it to Techking again.
 
Status
Not open for further replies.
Back
Top