Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int fact(int n)
- {
- if(n==0)
- return 1;
- else
- return n*fact(n-1);
- }
- void main()
- {
- int n,i,r,j;
- float c;
- printf("Enter number of rows in the table: ");
- scanf("%d",&n);
- float x[n],y[n];
- printf("Enter the values of x and y in the table:\n");
- for(i=0;i<n;i++)
- {
- scanf("%f",&x[i]);
- scanf("%f",&y[i]);
- }
- do
- {
- printf("Enter value of x at which u want to find y: ");
- scanf("%f",&c);
- float h=x[1]-x[0];
- float p=(c-x[0])/h;
- int t=n-1;
- float k[t];
- for(j=0;j<t;j++)
- {
- k[j]=y[j+1]-y[j];
- printf("%f ",k[j]);
- }
- printf("\n");
- int s[n-1];
- s[0]=k[0];
- for(i=1;i<n-1;i++)
- {
- t=n-1-i;
- float r[t];
- for(j=0;j<t;j++)
- {
- r[j]=k[j+1]-k[j];
- printf("%f ",r[j]);
- }
- s[i]=r[0];
- printf("\n");
- for(j=0;j<t;j++)
- {
- k[j]=r[j];
- }
- }
- float p_value[n-1];
- p_value[0]=p;
- for(i=1;i<n-1;i++)
- {
- p_value[i]=p_value[i-1]*(p-i);
- }
- float ans=y[0];
- for(i=0;i<n-1;i++)
- {
- ans+=(p_value[i]*s[i])/fact(i+1);
- }
- printf("%f\n",ans);
- printf("To continue press 0 and press 1 to exit: ");
- scanf("%d",&r);
- }
- while(r!=1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement