[ create a new paste ] login | about

Link: http://codepad.org/TdAhC78S    [ raw code | output | fork ]

C++, pasted on May 22:
/* Newton -Raphson method*/
#include<math.h>
#include<stdio.h>
float f(float x)
{
   float f;      
   f=x+log(x)-2;
      return(f);
}
          float df(float x)
            {
                  float df;
                  df=(1+1/x);
                  return (df);
            }
           // #define df(x) (x*cos(x))
                  main()
   {
                        float x[50],e,a,b;
                        int k;
                        printf("\n Enter accuracy  e=");
                        scanf("%f",&e);
                         do
                       {
                        printf("\n Enter interval a,b   ");
                         scanf("%f%f",&a,&b);
                        }while(f(a)*f(b)>0.0);
                        x[0]=(fabs(f(a))>fabs(f(b))?b:a);
                        printf("%f",x[0]);
                        k=0;
                        do
                        {
                  x[k+1]=x[k]-(f(x[k])/(df(x[k])));
       printf("\nk=%d  x[k]=%f  ",k,x[k]);
       k=k+1;
                        }
       while(fabs(x[k]-x[k-1])>=e && k<=20);
       printf("\n\n Root of the Equation is %f\n\n",x[k]);
       printf("\n No. of iterations =%d",k);
       getch();
      }


Output:
1
2
Line 17: error: ISO C++ forbids declaration of 'main' with no type
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: