稍微改动了你的代码,你试试。
有两处问题,你计算时是从最后一行开始计算的;c没有初始化。
有两处问题,你计算时是从最后一行开始计算的;c没有初始化。
程序代码:
#include <math.h> #include"string.h" #include"stdlib.h" #include <stdio.h> FILE *out; /* 0.9*0.8*0.7*0.6*0.5*0.4*0.3*0.2*0.1*1^0 0.9*0.8*0.7*0.6*0.5*0.4*0.3*0.2*0.9^1 0.9*0.8*0.7*0.6*0.5*0.4*0.3*0.8^2 0.9*0.8*0.7*0.6*0.5*0.4*0.7^3 0.9*0.8*0.7*0.6*0.5*0.6^4 0.9*0.8*0.7*0.6*0.5^5 0.9*0.8*0.7*0.4^6 0.9*0.8*0.3^7 0.9*0.2^8 0.1^9 */ int main(void) { long double m, n, c = 1, k = 10, h = k - 10, sum = 0, b, t, u, v, s = 10; //k为实际的孔数 out = fopen("E:\\收获1.txt", "wt"); for (m = 10; m >= 0; m--) //m为微滴进入的孔数 { u = m / k; v = k - m; b = pow(u, v); c = 1; for (n = k-1; n >= k + 1 - m; n--) c *= (n / s); t = b*c; sum = sum + t; fprintf(out, "%.12f\n", t); //%.6f意思是保留6位小数 } fprintf(out, "%.20f\n", sum); }