- #include<iostream>
- using namespace std;
- int main()
- {
- int N;
- cout<<"输入N的值:";
- cin>>N
- double x1 = 1;//初值
- double x2 = x1/2.0+N/2.0;
- while( fabs(x2-x1)>0.001)
- {
- x1 = x2;
- x2 = x1/2.0+N/2.0;
- }
- cout<<x1<<endl;
- return 0;
- }
求一个正整数N的开方,要求不能用库函数sqrt(),结果的精度在0.001
最新推荐文章于 2020-05-25 20:22:29 发布