Decimal Places

Lab C++ Beginner 10 points

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
Sample output available
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;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD