Advertisement
Md_hosen_zisad

newton

May 19th, 2019
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. #define f(x) sin(x)-1+x*x
  4. #define g(x) cos(x)+2*x
  5. #define E 0.001
  6.  
  7.  
  8. int main(){
  9.     int i=1;
  10.     float x0,x1,x2,f0,g0,root;
  11.  
  12.     printf("\n Enter the value of x0");
  13.  
  14.     scanf("%f",&x0);
  15.    printf("step\tx0        \tx1        \tf0        \tg0\n");
  16.     b:f0=f(x0);
  17.     g0=g(x0);
  18.     x1=x0-(f0/g0);
  19.     printf("%d\t %4f\t %4f\t %4f  \t%4f \n",i,x0,x1,f0,g0);
  20.     i++;
  21.     if(fabs((x1-x0)/x1)<=E){
  22.         root=x1;
  23.         printf("The root is %f",root);
  24.         goto c;}
  25.         else {
  26.             x0=x1;
  27.             goto b ;
  28.         }
  29.         c:
  30.             getch();
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement