Advertisement
orneto

newton

Jun 24th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. double x[10], y[10], p[10], k;
  6. int n,i,j=1;
  7. double f,f1=1,f2=0;
  8. printf("Entre com o valor de n:\n");
  9. scanf("%d", &n);
  10.  
  11. printf("Entre com os valore de x:\n");
  12. for (i=1;i<=n;i++)
  13. scanf("%lf", &x[i]);
  14.  
  15. printf("Entre com os valores correspondentes de y:\n");
  16. for (i=1;i<=n;i++)
  17. scanf("%lf", &y[i]);
  18.  
  19. f=y[1];
  20. printf("Entre com o valor de x que deseja encontrar o y:\n");
  21. scanf("%lf", &k);
  22.  
  23. while(n!=1){
  24. for (i=1;i<=n-1;i++)
  25. {
  26. p[i] = ((y[i+1]-y[i])/(x[i+j]-x[i]));
  27. y[i]=p[i];
  28. }
  29. f1=1;
  30. for(i=1;i<=j;i++)
  31. {
  32. f1*=(k-x[i]);
  33. }
  34. f2+=(y[1]*f1);
  35. n--;
  36. j++;
  37. }
  38.  
  39. f+=f2;
  40. printf("f(%lf) = %lf", k , f);
  41. getch();
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement