Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- double fact(double x)
- {
- if(x==1)
- return 1;
- else
- return (x*fact(x-1));
- }
- void main()
- {
- int n,i,j;
- double x[100],y[100][100],xp,u,l,t,sum=0,a,ans,k;
- printf("enter the number of values to be entered\n");
- scanf("%d",&n);
- printf("enter the values of x and y respectly\n");
- for(i=0;i<n;i++)
- scanf("%lf %lf",&x[i],&y[0][i]);
- printf("the values of x and y are\nx:\t");
- for(i=0;i<n;i++)
- printf("%.0lf ",x[i]);
- printf("\ny:\t");
- for(i=0;i<n;i++)
- printf("%.4lf ",y[0][i]);
- printf("\n(dell)y:\t");
- i=0;
- k=n;
- n--;
- do
- {
- i++;
- for(j=0;j<n;j++)
- {
- y[i][j]=y[i-1][j+1]-y[i-1][j];
- printf("%.4lf ",y[i][j]);
- }
- n--;
- if((i+1)<k)
- printf("\n(dell)%dy:\t",(i+1));
- }while(i<k);
- printf("\nenter the value to be calculated\n");
- scanf("%lf",&xp);
- u=(xp-x[0])/(x[1]-x[0]);
- l=u;
- for(i=1;i<(k-1);i++)
- {
- u=u*(l-i);
- t=fact(i+1);
- a=(u*y[i+1][0])/t;
- sum=sum+a;
- }
- ans=y[0][0]+(l*y[1][0])+sum;
- printf("the answer is %.4lf\n",ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment