Files
cmlab/4.c
Amneesh Singh be590b5cfd exp 1-6: init
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
2022-12-26 19:14:30 +05:30

34 lines
605 B
C

#include <stdio.h>
int main() {
double xp, yp = 0, p;
int i, j, n;
printf("Number of inputs: ");
scanf("%d", &n);
double x[n], y[n];
printf("Input sample space:\n");
for (i = 0; i < n; i++) {
printf("x%d: ", i);
scanf("%lf", x + i);
printf("y%d: ", i);
scanf("%lf", y + i);
}
printf("Enter interpolation point x: ");
scanf("%lf", &xp);
for (i = 0; i < n; i++) {
p = 1;
for (j = 0; j < n; j++) {
if (i != j) {
p *= (xp - x[j]) / (x[i] - x[j]);
}
}
yp += p * y[i];
}
printf("Interpolated value for %lf is %lf.", xp, yp);
}