参考代码:
#include <iostream> #include <math.h> #include <iomanip> using namespace std; int main() { double a,b,x1,x2; cin>>a; x1=a/2.0; x2=(x1+a/x1)/2.0; while(x1-x2>0.00001) { x1=(x2+a/x2)/2; x2=(x1+a/x1)/2; if(x1-x2<=0.00001) { break; } } if(x1-x2<=0.00001) { cout<<fixed<<setprecision(3)<<x1<<endl; } return 0; }
0.0分
0 人评分
C语言训练-字符串正反连接 (C语言代码)浏览:622 |
【明明的随机数】 (C++代码)浏览:781 |
拆分位数 (C语言代码)浏览:1328 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1162 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:611 |
打印十字图 (C语言代码)浏览:2710 |
Minesweeper (C语言描述,蓝桥杯)浏览:1126 |
循环入门练习6 (C语言代码)浏览:969 |
模拟计算器 (C语言代码)浏览:2300 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:501 |