idastan97

CSCI151 L27 P3

Nov 10th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. double f(double x){
  4.     return x*x*x+2*x*x-2;  
  5. }
  6.  
  7. double zeroFinder(double min, double max){
  8.     double mid=(max+min)/2.0;
  9.     if (f(mid)<=0.00001 && f(mid)>=-0.00001){
  10.         return mid;
  11.     } else if (f(mid)>0.00001){
  12.         return zeroFinder(min, mid);
  13.     } else {
  14.         return zeroFinder(mid, max);
  15.     }
  16. }
  17.  
  18. int main(void) {
  19.     printf("%f", zeroFinder(0.0, 1.0));
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment