Floating Point Issues

Q1: 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;
}

A 4.320000e+01, 43.200001, 43.2

B 4.3, 43.22, 43.21

C 4.3e, 43.20f, 43.00

D Error

ANS:A - 4.320000e+01, 43.200001, 43.2

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.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.