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 ?    10 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

number of times a digit is present in a number

1537


Write a program to print fibonacci series using recursion?

581


Can we assign integer value to char in c?

609


What is default value of global variable in c?

555


How do I get an accurate error status return from system on ms-dos?

639






What is external variable in c?

605


if (i = 0)printf ("True"); elseprintf("False"); Under what conditions will the above print out the string "True" a) Never b) Always c) When the value of i is 0 d) all of the above

705


What is the meaning of ?

607


Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?

613


Where are local variables stored in c?

562


What is the difference between c and python?

575


What does emoji p mean?

593


Is there any possibility to create customized header file with c programming language?

615


What is substring in c?

631


What is sizeof array?

600