これは私のC++を初めて使用したもので、以下のような宿題が割り当てられています。C++平方根を精度で求めること
- 平方根を求める精度を求めるプログラムを作成する必要があります。 (1)平方根を求める値と、(2)結果に必要な精度の小数点以下の桁数の2つの数字を入力するようにプログラムを開始します。次の最高の正方形と次の最低の完全な正方形をそれぞれ決定するループを使用します。その後、カウント制御ループを構築する必要があります。必要な小数点位置ごとに1回実行されます。
- このカウント制御ループの1回のパスでは、実際の値が渡されるまで、近似値はΔ= 1/10decimalPositionだけ増分または減分されます。ループの最初のパスでは、Δは1/10 = 0.1となります。 2回目のパスでは、Δは1/10 = 0.01となります。近似が小さすぎる場合、カウント制御ループ内のイベント制御ループは、大きすぎるまで近似値をインクリメントします。
私は彼らが私には意味がありません の指示にもかかわらず、段落2における処理のためのループを構築する起動方法などわかりませんよ。これまで
私の進捗状況:
int
sqroot()
{
cout << setiosflags (ios::fixed|ios::showpoint); //assumed I need for output later
double number;
cout<<"Enter the number to find the square root of: ";
cin>>number;
int sqRoot = 1;
while (sqRoot*sqRoot < number) // sqRoot is too small
sqRoot++; // try the next number
int y=0;
int newRoot =1;
while (y < number)
{
if (newRoot*newRoot > number)
break;
y=newRoot*newRoot;
newRoot++;
}
int decimalInput;
int decimalPosition= 0;
cout<<"Enter the desired decimal position: "<<endl;
cin>>decimalInput;
while (decimalPosition < decimalInput)
decimalPosition++;
return 0;
}
本当にAが必要な場合は、相対参照エラーを追加してください。http://en.wikipedia.org/wiki/Methods_of_computing_square_roots – pyCthon