Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include<stdio.h>
  2. int fact(int n)
  3. {
  4. if(n==0)
  5. return 1;
  6. else
  7. return n*fact(n-1);
  8. }
  9. void main()
  10. {
  11. int n,i,j;
  12. float c;
  13. printf("Enter number of rows in the table: ");
  14. scanf("%d",&n);
  15. float x[n],y[n];
  16. printf("Enter the values of x and y in the table:\n");
  17. for(i=0;i<n;i++)
  18. {
  19. scanf("%f",&x[i]);
  20. scanf("%f",&y[i]);
  21. }
  22. printf("Enter value of x at which u want to find y: ");
  23. scanf("%f",&c);
  24. float h=x[1]-x[0];
  25. float p=(c-x[n-1])/h;
  26. int t=n-1;
  27. float k[t];
  28. for(j=0;j<t;j++)
  29. {
  30. k[j]=y[j+1]-y[j];
  31. printf("%f ",k[j]);
  32. }
  33. printf("\n");
  34. float s[n-1];
  35. s[0]=k[t-1];
  36. for(i=1;i<n-1;i++)
  37. {
  38. t=n-1-i;
  39. float r[t];
  40. for(j=0;j<t;j++)
  41. {
  42. r[j]=k[j+1]-k[j];
  43. printf("%f ",r[j]);
  44. }
  45. s[i]=r[t-1];
  46. printf("\n");
  47. for(j=0;j<t;j++)
  48. {
  49. k[j]=r[j];
  50. }
  51. }
  52. //for(i=0;i<n-1;i++)
  53. //{
  54. // printf("%f \n",s[i]);
  55. //}
  56. float p_value[n-1];
  57. p_value[0]=p;
  58. for(i=1;i<n-1;i++)
  59. {
  60. p_value[i]=p_value[i-1]*(p+i);
  61. }
  62. float ans=y[n-1];
  63. for(i=0;i<n-1;i++)
  64. {
  65. ans+=(p_value[i]*s[i])/fact(i+1);
  66. }
  67. printf("%f\n",ans);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement