#include <stdio.h>
#include <math.h>

#define PI 3.14159265359
#define ACCURACY 1e-15

double fun(double x){
//       return exp(x)-2.0; 
//       return 0.5-cos(x);

//         return x-cos(x);

           return 
           
           pow(2,x)-10;
}

void bisection(){
     double xl=0, xr=4, xm=(xl+xr)/2.0;
     double fxl=fun(xl), fxr=fun(xr), fxm=fun(xm);
     
     int step=0;
         
     while(fabs(xl-xr)>ACCURACY){
                  printf("%2d %1.12lf %1.12lf %1.12lf",step,xl,xr,fxm);
                  
                  if(fxl*fxm<0){
                                       xr=xm;
                                       fxr=fxm;
                  }
                  else{
                      xl=xm;
                      fxl=fxm;             
                  }
                  
                  xm=(xl+xr)/2.0;
                  fxm=fun(xm);
                  
                  step++;
                  getchar();
     }
     printf("\nSolution:\n");
     printf("%2d %1.10lf %1.10lf %1.10lf",step,xl,xr,fxm);
               
}


main(){
       bisection();
       
       getchar();
       getchar();
       
       return 0;
}
