Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- #define f(x) sin(x)-1+x*x
- #define g(x) cos(x)+2*x
- #define E 0.001
- int main(){
- int i=1;
- float x0,x1,x2,f0,g0,root;
- printf("\n Enter the value of x0");
- scanf("%f",&x0);
- printf("step\tx0 \tx1 \tf0 \tg0\n");
- b:f0=f(x0);
- g0=g(x0);
- x1=x0-(f0/g0);
- printf("%d\t %4f\t %4f\t %4f \t%4f \n",i,x0,x1,f0,g0);
- i++;
- if(fabs((x1-x0)/x1)<=E){
- root=x1;
- printf("The root is %f",root);
- goto c;}
- else {
- x0=x1;
- goto b ;
- }
- c:
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement