1 条题解
-
0
C :
#include <stdio.h> #include <stdlib.h> #define p 1e-6 int main(int argc, char *argv[]) { float m,x; scanf("%f",&m); x=m; while(fabs(x*x-m)>=p) x=0.5f*(x+m/x); printf("%.3f\n",x); return 0; }
C++ :
#include<iostream> #include<cmath> #include<cstdio> using namespace std; int main() { double a,x0,x1; cin>>a; x0=a/2; x1=(x0+a/x0)/2; while (fabs(x1-x0)>1e-5) { x0=x1; x1=(x0+a/x0)/2; } printf("%.3lf\n",x1); return 0; }
Pascal :
var n:longint; begin readln(n); writeln(sqrt(n):0:3); end.
- 1
信息
- ID
- 1506
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者