Decimal Places
Completed
Print 22.0/7 with fixed and setprecision(2), then with setprecision(5), each on its own line.
Input
None.
Output
Two lines.
Example
Output
3.14 3.14286
Editor
C++
Hints
#include <iomanip> for setprecision.
fixed means the precision counts digits after the point.
Solution explanation
Manipulators change the stream's state and stay in effect until changed again.
Show solution
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double x = 22.0 / 7;
cout << fixed << setprecision(2) << x << "\n";
cout << setprecision(5) << x << "\n";
return 0;
}