Untitled
unknown
plain_text
2 years ago
862 B
3
Indexable
#include <stdio.h>
int fact(int n){
if(i<=1)
return 1;
else
return n*(n-1);
}
int main(){
int n,i,j;
float xp,x[i],y[i],fd[i];
printf("Enter the number of points: ");
scanf("%d",&n);
printf("\n Enter the value at which interpolated value is needed: ");
scanf("%f",&x);
for (i=0;i<n;i++){
printf("\n Enter data %d: ",i+1);
scanf("%f",&x[i]);
printf("Enter the corresponding value of data %d: ",i+1);
scanf("%f",&y[i]);
}
float x;
float h=x[1]-x[0];
float s=(x-x[0])/h;
for(i=0;i<n;i++){
fd[i]=y[i];
}
for(i=0;i<n;i++){
for(j=n-1;j>=i+1;j--){
fd[j]=fd[j]-fd[j-1];
}
}
float v=fd[0],p=1;
for(int i=0;i<n;i++){
for(int k=1;k=i;k++){
p=p*(s-k+1);
}
v=v+(fd[i]*p)/fact(i);
p=1;
}
printf("\n The interpolated value is %f ",v);
return 0;
}Editor is loading...