C++ Precision Program
Sets the decimal precision to be used to format floating-point values on output operations. Behaves as if member precision were called with n as argument on the stream on which it is inserted/extracted as a manipulator (it can be inserted/extracted on input streams or output streams).
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
cout<<"pre set to 3 digit\n\n";
cout.precision(3);
cout.width(10);
cout<<"value";
cout.width(15);
cout<<"sqrt of value"<<"\n";
for(int n=1;n<=5;n++)
{
cout.width(8);
cout<<n;
cout.width(13);
cout<<sqrt(n)<<"\n";
}
cout<<"\n set precision set of 5 digit \n\n";
cout.precision(5);
cout<<"sqrt(10)="<<sqrt(10)<<"\n\n";
cout.precision(0);
cout<<"sqrt(10)="<<sqrt(10)<<"(default setting\n";
return 0;
}
--------------------------------------------------------------------------------------------------------------------------
Output With Example
C++ Precision Program |
No comments:
Post a Comment
Please Comment Your Valuable Feedback....