43 lines
708 B
C
43 lines
708 B
C
#include <stdio.h>
|
|
|
|
int main() {
|
|
int n, i, j = 1;
|
|
double xp, yp, f1, f2 = 0;
|
|
|
|
printf("Enter the number of inputs: ");
|
|
scanf("%d", &n);
|
|
|
|
double x[n], y[n];
|
|
|
|
printf("Enter input values:\n");
|
|
for (i = 0; i < n; i++) {
|
|
printf("x%d=", i);
|
|
scanf("%lf", x + i);
|
|
printf("y%d=", i);
|
|
scanf("%lf", y + i);
|
|
}
|
|
|
|
yp = y[0];
|
|
|
|
printf("Enter interpolation point x: ");
|
|
scanf("%lf", &xp);
|
|
|
|
do {
|
|
for (i = 0; i < n - 1; i++)
|
|
y[i] = ((y[i + 1] - y[i]) / (x[i + j] - x[i]));
|
|
|
|
f1 = 1;
|
|
|
|
for (i = 0; i < j; i++) {
|
|
f1 *= (xp - x[i]);
|
|
}
|
|
|
|
f2 += (y[0] * f1);
|
|
j++;
|
|
} while ((--n) > 1);
|
|
|
|
yp += f2;
|
|
|
|
printf("Interpolated value for %lf is %lf.", xp, yp);
|
|
}
|