Advertisement
lily09290110

解平方根

Jan 7th, 2015
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4. #define elsp 0.005
  5. void calculation(double lg,double x)
  6. {
  7. double ng=0;
  8. ng=0.5*(lg+x/lg);
  9. if(fabs(ng-lg)>=elsp){
  10. calculation(ng,x);
  11. }
  12. else printf("ans : %.2lf",ng);
  13. }
  14. int main()
  15. {
  16. double x,lg=1.0;
  17. printf("please input a number : ");
  18. scanf("%lf",&x);
  19. calculation(lg,x);
  20. return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement