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's the best way of making my program efficient?

842


List the difference between a 'copy constructor' and a 'assignment operator' in C?

858


write a program fibonacci series and palindrome program in c

812


What is meant by int main ()?

957


which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;

2892


Which is best book for data structures in c?

829


What is identifiers in c with examples?

897


What is getch c?

1055


What is spaghetti programming?

884


Difference between linking and loading?

902


What does printf does?

992


Explain the binary height balanced tree?

914


How can you find the day of the week given the date?

857


what is a function method?give example?

2134


I came across some code that puts a (void) cast before each call to printf. Why?

975