解题思路:
注意事项:不建议用goto语句,可改为while/do while,这里只是提供思路。
参考代码:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double a, x, y;
cin >> a;
x = int(sqrt(a)) + 1;
loop: y = ( x + a/x )/2;
if ( fabs(y - x) > 0.00001)
{ x = y;
goto loop;
}
else cout<<fixed<<setprecision(3)<<y;
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.2 (C语言代码)浏览:5232 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:1099 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:595 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:1434 |
DNA (C语言代码)浏览:540 |
C语言程序设计教程(第三版)课后习题10.1 (C语言代码)浏览:567 |
【偶数求和】 (C语言代码)浏览:431 |
图形输出 (C语言代码)浏览:946 |
数组输出 (C语言代码)浏览:703 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:686 |