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
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 ? | 11 Yes | 0 No |
Post New Answer View All Answers
How do you determine whether to use a stream function or a low-level function?
Are comments included during the compilation stage and placed in the EXE file as well?
Write a program to generate random numbers in c?
What is the use of pragma in embedded c?
What is define c?
How old is c programming language?
Can we use any name in place of argv and argc as command line arguments?
Can a program have two main functions?
What is string function c?
In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none
Explain the priority queues?
What is a stream in c programming?
Is it possible to initialize a variable at the time it was declared?
When would you use a pointer to a function?
Is it better to use a macro or a function?