#include<iostream>
#include<iomanip>
using std::cout;
using std::cin;
using std::setw;
using std::endl;
using std::streamsize;
using std::setprecision;
int digits(double n,int places)
{
int result=places;
while(n>=1){
++result;
n/=10;
}
return result;
}
int main()
{
const double max_base = 99.9;
int max_base_width = digits(max_base, 2);
int max_result_width = digits(max_base * max_base, 2);
for (double i = 1; i <= max_base; i += 0.1)
{
streamsize prec= cout.precision();
cout << setw(max_base_width + 2) <<
setprecision(max_base_width) << i
<< setw(max_result_width + 2)
<< setprecision(max_result_width) << (i * i)
<<setprecision(prec)<< endl;
}
system("pause");
return 0;
}
Accelerated C++ Exercise 4-4
最新推荐文章于 2016-04-19 09:16:27 发布