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

42
5.c Normal file
View File

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