**基本上我得到了伪代码:
"x = 1
重复 10 次:x = (x + n / x) / 2
返回 x"
最后是int main函数的伪代码(int main函数打印出我在cout中的n个值),以便创建一个sqrt函数程序。我在 linux2 编译器上收到以下错误:
:在函数'double my_sqrt_1(double)'中:
:9:1: 错误:“return”之前的预期主表达式</p>
:9:1: 错误:预期 ';' 在'返回'之前</p>
:在函数'int main()'中::15:13:错误:'-'令牌之前的预期不合格ID
:~> 'return' 之前的预期主表达式</p>
非常感谢您的帮助!
#include <iostream>
#include <math.h>
using namespace std;
double my_sqrt_1(double n)
{
for (int x= 1; x<10; ++x)
cout<< x << '\t' << x=(x+n/x)/2 <<
return x;
}
int main()
{
int n= 3.141459;
int k= -100,-10,-1,0,1,10,and 100;
for(auto k : { -100,-10,-1,0,1,10,100}){
n=3.14159 * pow (10.0,k);
cout << "print n,sqrt(n),and my_sqrt_1(n)" ;
return 0;
}
}