Program that displays the values of different variables using setprecision.

Topic:

'setprecision' Manipulator in C++ Manipulators

Problem:

Write a program that displays the values of different variables using setprecision.

Solution:

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int main ()
{
cout<<endl<<endl<<endl;
double r,n1=132.364, n2=26.91;
r=n1/n2;
cout<<r<<endl;
cout<<setprecision(5)<<r<<endl;
cout<<setprecision(4)<<r<<endl;
cout<<setprecision(3)<<r<<endl;
cout<<setprecision(2)<<r<<endl;
cout<<setprecision(1)<<r<<endl;
getch();
}

Output:


Let me know in the comment section if you have any question.

Previous Post:

Next Post: