NiKlous


私信TA

用户名:NCL

访问量:8366

签 名:

等  级
排  名 4984
经  验 1524
参赛次数 0
文章发表 12
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

解题思路:





注意事项:不建议用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 人评分

  评论区