Given three variables, a, b, c, of type double that have already been declared and initialized, write some code that prints each of them in scientific (also known as e-notation or exponential notation) in a 10 position field on the same line. Each number should be printed with 3 digits to the right of the decimal point. For example, if their values were 987654321, 1234, 0.00987654321, the output would be: |x9.877e+08×1.234e+03×9.877e-03 NOTE: The vertical bar, |, on the left above represents the left edge of the print area; it is not to be printed out. Also, we show x in the output above to represent spaces–your output should not actually have x’s!

LANGUAGE: C++

CHALLENGE:

Given three variables, a, b, c, of type double that have already been declared and initialized, write some code that prints each of them in scientific (also known as e-notation or exponential notation) in a 10 position field on the same line. Each number should be printed with 3 digits to the right of the decimal point. For example, if their values were 987654321, 1234, 0.00987654321, the output would be: |x9.877e+08×1.234e+03×9.877e-03 NOTE: The vertical bar, |, on the left above represents the left edge of the print area; it is not to be printed out. Also, we show x in the output above to represent spaces–your output should not actually have x’s!

SOLUTION:



cout << scientific;
cout << setprecision(3);
cout << setw(10) << a;
cout << setw(10) << b;
cout << setw(10) << c;