LearnFrenzy
Sign in Take a free test

Input/Output with cin and cout · Predict the Output · Question 17

Default precision of cout for large and small doubles Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 17 Back to Exercise

What is the output of the following C++ program?

main.cpp
#include <iostream>

int main() {
    std::cout << 1234567.0 << ' ' << 123456.0 << ' ' << 0.0001234 << ' ' << 100.0 << ' ' << 2.50 << '\n';
    return 0;
}
  • A 1.23457e+06 123456 0.0001234 100 2.5 Correct
  • B 1234567 123456 0.0001234 100 2.50
  • C 1.23457e+06 123456 1.234e-04 100.0 2.5
  • D 1234567.0 123456.0 0.0001234 100.0 2.50
Correct Answer: Option A

Default notation uses 6 significant digits and switches to scientific when the number needs more than 6 digits before the point. Trailing zeros and the point of whole numbers are dropped.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links