C Programming - Floating Point Issues - Discussion
Discussion Forum : Floating Point Issues - Find Output of Program (Q.No. 6)
6.
What will be the output of the program?
#include<stdio.h>
int main()
{
float f=43.20;
printf("%e, ", f);
printf("%f, ", f);
printf("%g", f);
return 0;
}
Answer: Option
Explanation:
printf("%e, ", f); Here '%e' specifies the "Scientific Notation" format. So, it prints the 43.20 as 4.320000e+01.
printf("%f, ", f); Here '%f' specifies the "Decimal Floating Point" format. So, it prints the 43.20 as 43.200001.
printf("%g, ", f); Here '%g' "Use the shorter of %e or %f". So, it prints the 43.20 as 43.2.
Discussion:
6 comments Page 1 of 1.
Vivek dutt said:
5 years ago
Why it is 43.2000001?
Puja said:
6 years ago
Why 43.2000001?
Asha said:
1 decade ago
I cant understand this program. Can anyone explain how %e,%g,%f works in C and explain about it in detail ?
Sagar said:
1 decade ago
In the above problem
Why printf ("%f", f) ; Statement prints the 43.200001 other than 43.200000 ?
Why printf ("%f", f) ; Statement prints the 43.200001 other than 43.200000 ?
Shyam said:
1 decade ago
In the above problem
why printf ("%f", f) ; statement prints the 43. 200001 other than 43. 200000 ?
why printf ("%f", f) ; statement prints the 43. 200001 other than 43. 200000 ?
Saki__001 said:
1 decade ago
Can anybody explain how various notations works?
i.e %e, %f, %g and such all in details.
i.e %e, %f, %g and such all in details.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers