The 275.7 and 75.7 are doubles. The assignment statements round the double constant to float precision. Then you compare the unrounded double to the rounded float. If you had used 275.7e0 and 75.7e0 in the if statements, the results would have been "Hello" in both cases.
Or to put it differently, 275.7 != 275.7e0 (not surprising) and 75.7 ! = 75.7e0 (ditto), but one double is greater than the float because the double is rounded down to form the float and the other is less than the float because the double is rounded up to form the float. Dave On Jan 8, 8:24 pm, priya mehta <[email protected]> wrote: > #include<stdio.h> > int main() > { > float a=275.7; > if(275.7>a) > printf("Hi"); > else > printf("Hello"); > return 0; > > } > > #include<stdio.h> > int main() > { > float a=75.7; > if(75.7>a) > printf("Hi"); > else > printf("Hello"); > return 0; > > } > > why the above two programs give different output? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
