#include < stdio.h >
#define FMT "%-10.5g"
#define N 11
typedef float FLT[N];
float Ih(FLT x, FLT f, int k, float xx) {
return (xx - x[k + 1]) / (x[k] - x[k + 1]) * f[k] + (xx - x[k]) / (x[k + 1] - x[k]) * f[k + 1];
}
void main() {
int i;
FLT x,
f;
float xx,
yy;
for (i = 0; i < N; i++) {
x = (float)(i - 5);
f = 1 / (1 + x * x);
}
printf("\nIh(x):\n");
for (i = 0; i < N - 1; i++) {
xx = 0.5 * (x + x);
yy = Ih(x, f, i, xx);
printf(FMT, yy);
}
printf("\nf(x):\n");
for (i = 0; i < N - 1; i++) {
xx = 0.5 * (x + x);
yy = 1 / (1 + xx * xx);
printf(FMT, yy);
}
}
标签:FMT,float,FLT,yy,xx,printf,fdxxcz From: https://blog.51cto.com/u_16076050/6195962