Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. double heron(double zahl);
  6.  
  7. int main()
  8. {
  9.     double a = -2;
  10.     printf("heron: %f\nsqrt: %f", heron(a), sqrt(a));
  11. }
  12.  
  13. double heron(double zahl){
  14.     double x;
  15.     double x_old;
  16.     if(zahl >= 0) {
  17.         x = (zahl +1)/2;
  18.         while(fabs(x-x_old) > 10E-5) {
  19.             x_old = x;
  20.             x = (x+(zahl/x))/2;
  21.         } return x;
  22.     } else {
  23.         printf("Die übergebene Zahl ist negativ!\n");
  24.         return NAN;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement