/*************************************************************\
This example is well orgainzed, all the beginning and end of
loops and function are aligned, it is very easy to see where
is the beginning and end of a loop even there is no statement
to show where it is.
\*************************************************************/
#include <stdio.h>

double   pn;
double   p;
double   answer;
int          count1;
int          count2;
double   f(double);
double   f1(double);
double   a;
double   b;
double   xn;
double   temp;
double   left;
double   lefty;
double   right;
double   righty;

void main()
{
    a = 0;
    b = 0;
    printf ("\nPoint a = ");
    scanf("%lf", &a) ;
    printf ("\nPoint b = ");
    scanf("%lf", &b) ;
    printf ("\n");
    left       =   a;
    right     =   b;
    pn        =   (left+right)/2;
    answer =   f(pn);

    while ((answer<-0.1)||(answer>0.1))
    {
        lefty  =  f(left);
        righty =  f(right);

        if ((lefty >0 && answer >0)||(lefty<0 && answer < 0))
        {
            left = pn;
        }
        else if ((righty >0 && answer >0)||(righty<0 && answer < 0))
        {
            right = pn;
        }

        pn        = (left+right)/2;
        answer = f(pn);
        count1++;
    }

    xn        = pn;
    answer = f(xn);

    while ((answer<-0.000001)||(answer>0.000001))
    {
        temp    = xn-(f(xn)/f1(xn));
        xn        = temp;
        answer = f(xn);
        count2++;
    }

     printf ( " N = %.8d pn = %.8f\n" , count1, pn);
    printf ( " K = %.8d xk = %.8f\n\n" , count2, xn);
}

double f(double lnn)
{
    double answer;
    answer = exp(10*(1-lnn));
    return answer;
}

double f1(double lnn)
{
    double answer;
    answer = -10*2.718281828*(10*(1-lnn));
    return answer;
}