Given three variables, a, b, c, of type double that have already been declared a
ID: 3890632 • Letter: G
Question
Given three variables, a, b, c, of type double that have already been declared and initialized, write a statement that prints each of them on the same line, separated by one space, in such a way that scientific (or e-notation or exponential notation) is avoided. Each number should be printed with 5 digits to the right of the decimal point. For example, if their values were 4.014268319, 14309, 0.00937608, the output would be: |4.01427x14309.00000x0.00938 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!
C++
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double a,b,c;
a = 4.014268319;
b = 14309;
c = 0.00937608;
cout<<fixed<<setprecision(5); //using header file functions,cout format is set fixed with precision of 5 digits
cout<<a<<" "<<b<<" "<<c;
return 0;
}
Output:
4.01427 14309.00000 0.00938
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.