hello..
i was solving question and suddenly i came across this question
int main()
{
float pi=3.14,x=2.5;
int a,b;
a=(pi==3.14);
b=(x==2.5);
printf("%d,%d"a,b);
return 0;
}
the ans given there was 0,1
but it should be either 0,0 or 1,1...this baffled me. So pls give me the reason for the ans. Thanx in advance..:)
The result I received was 1, 1, as expected according to you. You have a truncation warning as well as a missing comma within the printf( ) argument list (after the string literal).
Technically, the possible truncation of (float pi=3.14,x=2.5;) is not the problem but should point you to the problem.
pi==3.14, this is comparing a float with a double literal, comparing floating point types is error prone at best but worse when comparing different precisions.
@framework: hey hey man i 'm using oturboc because i'm familar to it....btw i have got the ans...
the ans is this turbo compiler divide the last digit into number of bits and if the last digit is 5 or greater than it the ans will be 1. so if we have enter 2 number like pi=3.15,x=2.5 we will get ans 1,1.....
and if we have enter number like pi=3.14,x=2.2(2.4) we will get ans o,o...:)