what is the output of the following program?
#include<stdio.h>
void main()
{
float x=1.1;
while(x==1.1)
{
printf("\n%f",x);
x=x-0.1;
}
}
Answer Posted / shibumon alampatta
No output; since (x == 1.1) will return false.
Explanantion:
First of all we shall look into the binary representation of
decimal number 1.1. It is 1.00011001100110011..... reccuring
infinite fractional part. And in the expression (x == 1.1),
x is a float and 1.1 is double constant. So their precisions
are different and float x = 1.1 and the double constant 1.1
will not be equal. So if we make double x = 1.1, instaed of
float it will work. Also if it is float x = 1.5 then the
expression (x == 1.5) will return true; because binary form
of 1.5 is 1.1; which is finite and both flaot and double
will have same value.
| Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
What is cohesion in c?
How many main () function we can have in a project?
How can I do serial ("comm") port I/O?
Which operators cannot be overloaded a) Sizeof b) .* c) :: d) all of the above
what is recursion in C
Can you please explain the difference between syntax vs logical error?
Why do we write return 0 in c?
Why doesnt long int work?
Give basis knowledge of web designing ...
What is an example of structure?
why return type of main is not necessary in linux
hi friends how r u as soon in satyam my interview is start but i m very confusued ta wat i do plz help me frndz wat can i do plz tell me some question and answers related with "C" which r asked in the interview .
What is the difference between the expression “++a” and “a++”?
Device an algorithm for weiler-atherton polygon clipping, where the clipping window can be any specified polygon
Can you subtract pointers from each other? Why would you?