Advertisement
JayaAhmed

Bisection Method

Oct 10th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. double func(double x)
  4. {
  5.     return x*x-4*x-10;
  6. }
  7.  
  8. int main()
  9. {
  10.     double a, b, c;
  11.  
  12.     scanf("%lf %lf", &a, &b);
  13.  
  14.     while(b-a>.0001)
  15.     {
  16.         c = ((a+b)/2);
  17.         if(func(a)*func(c)<0)
  18.             b=c;
  19.         else
  20.             a=c;
  21.     }
  22.  
  23.     printf("A root of the equation using bisection method is,\nX = %.4lf\n",(a+b)/2.0);
  24.  
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement