#include < stdio.h >
#define FMT "%-10.5g"
#define N 3
typedef float DBL[N];
float Lag(DBL x, DBL f, int n, float xx) {
int k,
j;
float r,
s = 0.0;
for (k = 0; k <= n; k++) {
r = 1.0;
for (j = 0; j <= n; j++) if (j != k) r *= (xx - x[j]) / (x[k] - x[j]);
s += f[k] * r;
}
return s;
}
void main() {
int i;
DBL x,
f;
float xx;
printf("\n");
for (i = 0; i < N; i++) {
printf("x[%d]=", i);
scanf("%f", x + i);
printf("f(%d)=", i);
scanf("%f", f + i);
}
printf("x=");
scanf("%f", &xx);
xx = Lag(x, f, N - 1, xx);
printf("\nf(x)=");
printf(FMT, xx);
}
标签:%-,typedef,DBL,int,float,Lagrange,define From: https://blog.51cto.com/u_16076050/6195960