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
number of times a digit is present in a number
Write a program to print fibonacci series using recursion?
Can we assign integer value to char in c?
What is default value of global variable in c?
How do I get an accurate error status return from system on ms-dos?
What is external variable in c?
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
What is the meaning of ?
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.?
Where are local variables stored in c?
What is the difference between c and python?
What does emoji p mean?
Is there any possibility to create customized header file with c programming language?
What is substring in c?
What is sizeof array?