C Programming - Floating Point Issues - Discussion
Discussion Forum : Floating Point Issues - Find Output of Program (Q.No. 1)
1.
What will be the output of the program?
#include<stdio.h>
int main()
{
float a=0.7;
if(a < 0.7)
printf("C\n");
else
printf("C++\n");
return 0;
}
Answer: Option
Explanation:
if(a < 0.7) here a is a float variable and 0.7 is a double constant. The float variable a is less than double constant 0.7. Hence the if condition is satisfied and it prints 'C'
Example:
#include<stdio.h>
int main()
{
float a=0.7;
printf("%.10f %.10f\n",0.7, a);
return 0;
}
Output:
0.7000000000 0.6999999881
Discussion:
21 comments Page 3 of 3.
Thangavel.V said:
1 decade ago
First what you should know float range value and double range value before to find out solution:
The range of double is -1.7e-308 to 1.7e+308.
The range of float is -3.4e-38 to 3.4e+38.
They are given float a=0.7---->(double constant,0.7)
(float value,a)
printf("%.10f %.10f\n",0.7, a);
0.7000000000 0.6999999881
Just you consider range value and solve it...whatever i know that only put.
The range of double is -1.7e-308 to 1.7e+308.
The range of float is -3.4e-38 to 3.4e+38.
They are given float a=0.7---->(double constant,0.7)
(float value,a)
printf("%.10f %.10f\n",0.7, a);
0.7000000000 0.6999999881
Just you consider range value and solve it...whatever i know that only put.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers