c语言 求组合数 定义分母分子 阶乘
#include<stdio.h>
// 函数声明,计算阶乘
double fact(int n);
int main() {
int m, n;
scanf("%d %d", &m, &n); // 修正变量名
printf("result=%lf", fact(n) / (fact(m) * fact(n - m))); // 修正公式和格式化字符串
return 0;
}
double fact(int n) {
double result = 1.0; // 修正为double类型
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}