Home » C Programming » Data Types » Question
  1. Which of the following is the correct output for the program given below?
    #include <stdio.h>
    int main ( )
    {
    double d = 2.25;
    printf ("%e", d);
    printf ("%f", d);
    printf ("%g".d);
    printf ("%lf\n", d);
    return 0 ;
    }
    1. 2.2 2.50 2.50 2.5
    2. 2.2e 2.25f 2.00 2.25
    3. 2.250000e + 000 2.250000 2.25 2.250000
    4. Error
Correct Option: C

printf("%e,", d); Here '%e' specifies the "Scientific Notation" format. So, it prints the 2.25 as 2.250000e+000.

printf("%f,", d); Here '%f' specifies the "Decimal Floating Point" format. So, it prints the 2.25 as 2.250000.

printf("%g,", d); Here '%g' "Use the shorter of %e or %f". So, it prints the 2.25 as 2.25.

printf("%lf,", d); Here '%lf' specifies the "Long Double" format. So, it prints the 2.25 as 2.250000.



Your comments will be displayed only after manual approval.