Question 3
Back to Exercise
What is the output of the following C++ program?
#include <iomanip>
#include <iostream>
int main() {
double x = 12.3456;
std::cout << std::setprecision(2) << x << ' '
<< std::fixed << x << ' '
<< std::scientific << x << '\n';
return 0;
}
- A 12 12.35 1.23e+01 Correct
- B 12.35 12.35 1.23e+01
- C 12 12.34 1.2e+01
- D 1.2e+01 12.35 1.23e+01
Correct Answer: Option A
Default notation: 2 significant digits → 12. fixed: 2 decimals → 12.35. scientific: 2 decimals in the mantissa → 1.23e+01.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!