C/C++の宿題を片付けます 99代目at TECH
C/C++の宿題を片付けます 99代目 - 暇つぶし2ch508:デフォルトの名無しさん
07/11/14 21:45:15
>>507
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
using namespace std;
struct succ{ int operator()(){ return _n++; } succ():_n(1){};int _n; };
struct print{
double qube( const int & n ) {
double x = 0, xn = 1;
while ( fabs( x-xn ) > 1.0e-8 ) { x = xn; xn = x-(x*x*x-n)/(3.0*x*x ); }
return xn;
}
void operator()( const int & n ){
cout<<setw(4)<<n<<" "<<setw(4)<<n*n<<" "<<setw(9)<<1.0/n<<" "<<setw(9)<<sqrt(n)<<" "<<setw(9)<<qube(n)<<endl; }
};

int main( int argc, char ** args ){
const int N = 25;
int v[N]={};
cout << setw(4) << "n"<<setw(4)<<"n^2"<<setw(9)<<"1/n"<<setw(9)<<"n^1/2"<<setw(9)<<"n^1/3"<<endl;
generate( v, v+N, succ());
for_each( v, v+N, print());
return 0;
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch