Q. Which of the following is the correct output for the program given below?

Code:
#include <stdio.h>
int main ( ) 
{
    float n = 5.375 ;
    printf("%f %e %E\n" , n, n, n) ;
    return 0 ;
}
  • (A) 5.375 5.375 5.375
  • (B) 5.375000 5.375000 5.375000
  • (C) 5.375000 5.375000e+000 5.375000E+000
  • (D) 5.375000 5.375000E+000 5.375000e+000
πŸ’¬ Discuss
βœ… Correct Answer: (C) 5.375000 5.375000e+000 5.375000E+000
Explanation:

The printf() function is used to print a floating-point number in different formats:

  • %f β†’ Prints the number in decimal notation (default floating-point format).
  • %e β†’ Prints the number in scientific notation (lowercase 'e').
  • %E β†’ Prints the number in scientific notation (uppercase 'E').

Breakdown of Output:

For n = 5.375:

  1. %f β†’ 5.375000 (default 6 decimal places)
  2. %e β†’ 5.375000e+000
  3. %E β†’ 5.375000E+000

Thus, the output is:

5.375000 5.375000e+000 5.375000E+000
Explanation by: Mr. Dubey

The printf() function is used to print a floating-point number in different formats:

  • %f β†’ Prints the number in decimal notation (default floating-point format).
  • %e β†’ Prints the number in scientific notation (lowercase 'e').
  • %E β†’ Prints the number in scientific notation (uppercase 'E').

Breakdown of Output:

For n = 5.375:

  1. %f β†’ 5.375000 (default 6 decimal places)
  2. %e β†’ 5.375000e+000
  3. %E β†’ 5.375000E+000

Thus, the output is:

5.375000 5.375000e+000 5.375000E+000

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
263
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Akash Lawaniya
Publisher
πŸ“ˆ
86%
Success Rate