exp 1-6: init

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-12-26 19:14:30 +05:30
commit be590b5cfd
9 changed files with 386 additions and 0 deletions

33
4.c Normal file
View File

@@ -0,0 +1,33 @@
#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);
}