#include <math.h>

typedef double reel;
 
typedef reel fonction( reel x );
reel f( reel x )
{
return sin( 2 * x ) - x;
} 
reel solve( fonction f, reel a, reel b)
    {  reel x, y;
       if ( f(a) > f(b) ) {
	  x = a;
          a = b;
          b = x;
       }
       while ( fabs( b - a ) > 0.0001 ){
	x = ( a + b ) / 2;
       	y = f( x );
        if  ( y > 0 ) b = x;
        else a = x; 
       }
       return a;
    }
    
fonction *test;

int main( void )
{
reel r;
test = f;
r = solve ( test, 0.5, 1.5 )  ;
printf("\nr=%.4f y=%.4f", r , test( r ));
return 0;
}
