Q. What will be the output of the following C code?

Code:
#include <stdio.h>

int main()
{
    float x = 23.456;
    printf("%.2f",x);
    return 0;
}
  • (A) 23.45600
  • (B) 23.456
  • (C) 23.45
  • (D) 23.46
πŸ’¬ Discuss
βœ… Correct Answer: (D) 23.46
Explanation: In the above code, the value of x is 23.456 and we are printing the value of x using the %.2f format specifier. %.2f rounds the value and prints the 2 digits after the decimal point.
Explanation by: Kanak Sharma
In the above code, the value of x is 23.456 and we are printing the value of x using the %.2f format specifier. %.2f rounds the value and prints the 2 digits after the decimal point.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
251
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Kanak Sharma
Publisher
πŸ“ˆ
99%
Success Rate