fork(1) download
  1. #include<stdio.h>
  2. int dyg(int a)
  3. {
  4. float x0,x1;
  5. x0=a/2;
  6. x1=0.5*(x0+a/x0);
  7. while(fabs(x1-x0)>1e-5)
  8. {
  9. x0=x1;
  10. x1=0.5*(x0+a/x0);
  11. }
  12. return x1;
  13. }
  14.  
  15. int main(void) {
  16. // your code goes here
  17. int a;
  18. float x;
  19. scanf("%d",&a);
  20. x=dyg(a);
  21. printf("%d的算术平方根是:%f",a,x);
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 5348KB
stdin
2
stdout
2的算术平方根是:1.000000