Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define f(x) ( (x*x*x*x) -x - 10)
- #define f1(x) ( (4*x*x*x) - 1)
- int main()
- {
- float x0,x1,E;
- int i,n;
- printf("Enter the value of x0,E,n\n");
- scanf("%f %f %d",&x0,&E,&n);
- for(i=1 ; i<=n ; i++){
- if(fabs(f1(x1)) <= E ){
- printf("Slope is too small \n");
- return 0;
- }
- x1 = x0 - (f(x0)/f1(x0));
- if(x0==x1){
- printf("Convergent solution\n");
- printf("Hence the root is %f\n",x1);
- printf("No. of interations %d\n",i);
- return 0;
- }
- x0 = x1;
- }
- printf("Eoes not converge in %d interations",i-1);
- return 0;
- }
- /*
- Output
- Enter the value of x0,d,n
- 2 0.001 5
- Convergent solution
- Hence the root is 1.855585
- No. of interations 4
- */
Add Comment
Please, Sign In to add comment