#include <stdio.h> #include <math.h> int main() { double a=0, b=1, L=0, R=0, e, f, g, h, i; e = 2*(a-1)+2*exp(-a)*(1-exp(-a)); f = 2*(b-1)+2*exp(-b)*(1-exp(-b)); for(i=1; i<=11; i++){ g = (a*f-b*e)/(f-e); h = 2*(g-1)+2*exp(-g)*(1-exp(-g)); printf("x1 = %f, x2 = %f, x3 = %f, N = %f ", a, b, g, i); if(fabs(h)<=0.000001){ printf ("\nroot = %f", g); return 0; } else{ if(e*h<0){ b = g; f = h; L++; R=0; if(L>1){ e = e/2; } } if(e*h>0){ a = g; e = h; R++; L=0; if(R>1){ f = f/2; } } } printf("KL = %f, KR = %f\n", L, R); if(fabs(h)<0.000001){ printf("\nroot = %f", g); return 0; } if(fabs((a-b))<0.0001){ printf("\nroot = %f", g); return 0; } if(i == 11){ printf("\nroot = %f", g); return 0; } } }