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


Please Help Members By Posting Answers For Below Questions

What does malloc () calloc () realloc () free () do?

570


Difference between exit() and _exit() function?

666


What is a string?

674


How do I get a null pointer in my programs?

636


Write a program to implement queue.

674






explain what is a newline escape sequence?

696


Explain how can I remove the trailing spaces from a string?

636


What is volatile variable in c with example?

594


Difference between MAC vs. IP Addressing

648


Why #include is used in c language?

607


the question is that what you have been doing all these periods (one year gap)

1633


On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area

675


What is the use of header files?

614


What is the difference between fread and fwrite function?

644


What is meant by gets in c?

617