Untitled
unknown
plain_text
2 years ago
711 B
7
Indexable
#include <stdio.h>
void main(){
int n,j,i;
printf("Enter the number of points: ");
scanf("%d",&n);
float x[n],y[n];
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 point;
printf("\n Enter the value at which interpolated value is needed: ");
scanf("%f",&point);
float dd[n];
for(i=0;i<n;i++){
for(j=n-1;j>=i+1;j=j-1){
dd[j]= (dd[j]-dd[j-1])/(x[j]-x[j-1-i]);
}
}
float v=0,p=1.0;
for(i=0;i<n;i++){
for(j=0;j<i;j++){
p=p*(point-x[j]);
}
v= v+dd[i]*p;
p=1;
}
printf("\n The interpolated value is %f ",v);
}Editor is loading...