Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define n 10
- #define x0 0
- double f(double x)
- {
- return (exp(-x)-x); // função a ser encontrada a raiz
- }
- double df(double x)
- {
- return (-exp(-x)-1); // derivada da função
- }
- int main(void)
- {
- double x=x0;
- int i,k=0;
- for (i=0;i<n;i++) // for (i=0;i<n && f(x)!=0;i++)
- {
- x=x-f(x)/df(x);
- printf("f(%e)=%e \n",x,f(x));
- k++;
- if (f(x)==0)
- break;
- }
- printf("Número de iterações: %d \n",k);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement