Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 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,r,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. do
  23. {
  24. printf("Enter value of x at which u want to find y: ");
  25. scanf("%f",&c);
  26. float h=x[1]-x[0];
  27. float p=(c-x[0])/h;
  28. int t=n-1;
  29. float k[t];
  30. for(j=0;j<t;j++)
  31. {
  32. k[j]=y[j+1]-y[j];
  33. printf("%f ",k[j]);
  34. }
  35. printf("\n");
  36. int s[n-1];
  37. s[0]=k[0];
  38. for(i=1;i<n-1;i++)
  39. {
  40. t=n-1-i;
  41. float r[t];
  42. for(j=0;j<t;j++)
  43. {
  44. r[j]=k[j+1]-k[j];
  45. printf("%f ",r[j]);
  46. }
  47. s[i]=r[0];
  48. printf("\n");
  49. for(j=0;j<t;j++)
  50. {
  51. k[j]=r[j];
  52. }
  53. }
  54. float p_value[n-1];
  55. p_value[0]=p;
  56. for(i=1;i<n-1;i++)
  57. {
  58. p_value[i]=p_value[i-1]*(p-i);
  59. }
  60. float ans=y[0];
  61. for(i=0;i<n-1;i++)
  62. {
  63. ans+=(p_value[i]*s[i])/fact(i+1);
  64. }
  65. printf("%f\n",ans);
  66. printf("To continue press 0 and press 1 to exit: ");
  67. scanf("%d",&r);
  68. }
  69. while(r!=1);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement