Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- double heron(double zahl);
- int main()
- {
- double a = -2;
- printf("heron: %f\nsqrt: %f", heron(a), sqrt(a));
- }
- double heron(double zahl){
- double x;
- double x_old;
- if(zahl >= 0) {
- x = (zahl +1)/2;
- while(fabs(x-x_old) > 10E-5) {
- x_old = x;
- x = (x+(zahl/x))/2;
- } return x;
- } else {
- printf("Die übergebene Zahl ist negativ!\n");
- return NAN;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement