Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int i,n,j,fact=1;
- float x[20],y[20][20],h,term=1,u,sum,xval;
- printf("Enter the value of n:");
- scanf("%d",&n);
- printf("\nEnter the elements of x: ");
- for(i=0 ; i<n ; i++){
- scanf("%f",&x[i]);
- }
- printf("Enter the elements of y: ");
- for(i=0 ; i<n ; i++){
- scanf("%f",&y[i][0]);
- }
- h=x[1]-x[0];
- printf("\nEnter x for which y is to be calculated:");
- scanf("%f",&xval);
- u = (xval - x[n-1] )/h;
- printf("\nh=%f u= %f",h,u);
- sum = y[n-1][0];
- for(j=1 ; j<n ; j++){
- for(i=0 ; i< (n-j) ; i++){
- // when j =2 then i =0 ,1 & when j =3 then i =0)
- y[i][j]=y[i+1][j-1] - y[i][j-1];
- }
- }
- printf("The table is :\n");
- for(i=0; i<n ; i++){
- printf("\t %.2f ",x[i]);
- for(j=0 ; j<(n-i)+1 ; j++){
- printf("\t%.2f,",y[i][j]);
- }
- printf("\n");
- }
- for(j=1 ; j<n ; j++){
- for(i=1 ; i<=j ; i++){
- fact = fact * i;
- }
- term = term * (u-(j-1));
- printf("\nTerm=%f",term);
- printf("\nFactorial=%d",fact);
- sum = sum + ((y[0][j] * term) / fact);
- fact = 1;
- }
- printf("\n\nfor x = %f the ultimate answer is sum = %f",xval,sum);
- return 0;
- }
- /*
- Enter the value of n:5
- Enter the elements of x: 1891
- 1901
- 1911
- 1921
- 1931
- Enter the elements of y: 12
- 15
- 20
- 27
- 39
- Enter x for which y is to be calculated:1925
- h=10.000000 u= -0.600000The table is :
- 1891.00 12.00, 3.00, 2.00, 0.00, 3.00, 0.00,
- 1901.00 15.00, 5.00, 2.00, 3.00, 0.00,
- 1911.00 20.00, 7.00, 5.00, 0.00,
- 1921.00 27.00, 12.00, -0.00,
- 1931.00 39.00, 0.00,
- Term=-0.600000
- Factorial=1
- Term=0.960000
- Factorial=2
- Term=-2.496000
- Factorial=6
- Term=8.985600
- Factorial=24
- for x = 1925.000000 the ultimate answer is sum = 39.283199
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement