Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- float fact(int x)
- {
- if(x==1)
- return 1;
- else
- return x*fact(x-1);
- }
- int main()
- {
- float y[10][10],x[10],u,t,a,ans,l,xp,sum;
- int n,i,j;
- printf("enter n ");
- scanf("%d",&n);
- printf("\n enter the x and y values");
- for(i=0;i<n;i++)
- {
- scanf("%f %f",&x[i],&y[0][i]);
- }
- for(i=0;i<n;i++)
- printf("\nx[%d]= %f \t y[%d]=%f",(i+1),x[i],(i+1),y[0][i]);
- i=0;
- printf("\n");
- printf("\n");
- do
- {
- i++;
- for(j=0;j<n-i;j++)
- {
- y[i][j]=y[i-1][j+1]-y[i-1][j];
- printf("y=%f\t",y[i][j]);
- }
- printf("\n");
- }while(i<n);
- printf("Enter the value to be calculated");
- scanf("%f",&xp);
- u=(xp-x[0])/(x[1]-x[0]);
- l=u;
- sum=0;
- a=0;
- for(i=1;i<n-1;i++)
- {
- u=u*(l-i);
- t=fact(i+1);
- a=(u*y[i+1][0])/t;
- sum+=a;
- }
- ans=y[0][0]+l*y[1][0]+sum;
- printf("\n\nthe ans is %f",ans);
- return 0;
- }
- OUTPUT:
- enter n 4
- enter the x and y values20
- .3420
- 23 .3907
- 26 .4384
- 29 .4848
- x[1]= 20.000000 y[1]=0.342000
- x[2]= 23.000000 y[2]=0.390700
- x[3]= 26.000000 y[3]=0.438400
- x[4]= 29.000000 y[4]=0.484800
- y=0.048700 y=0.047700 y=0.046400
- y=-0.001000 y=-0.001300
- y=-0.000300
- Enter the value to be calculated21
- the ans is 0.358326Press any key to continue
Advertisement
Add Comment
Please, Sign In to add comment