1 solutions
-
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
Information
- ID
- 16591
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By