1 solutions
-
0
C :
#include<stdio.h> #include<math.h> int main() { double a, x2, x1; scanf("%lf", &a); x2 = 1.0; do { x1 = x2; x2 = 0.5 * (x1 + a / x1); } while(fabs(x1 - x2) >= 1e-5); printf("%.3lf\n", x2); return 0; }C++ :
#include<iostream> #include<stdio.h> #include<math.h> using namespace std; int main() { double x1,x2,a; cin>>a; if(a>=0) { x2=1.0; do { x1=x2; x2=0.5*(x1+a/x1); } while(fabs(x2-x1)>=1e-5); printf("%.3f\n",x2); } return 0; }Pascal :
var s:longint; begin readln(s); writeln(sqrt(s):0:3); end.
- 1
Information
- ID
- 19331
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By