C语言实现宿舍分配方案数量计算
#include <stdio.h>
// 定义阶乘函数 int factorial(int n) { if (n == 0 || n == 1) { return 1; } else { return n * factorial(n-1); } }
// 定义组合数函数 int combination(int n, int m) { return factorial(n) / (factorial(m) * factorial(n-m)); }
int main() { int n, m; printf('请输入学生数量n和房间数量m:'); scanf('%d %d', &n, &m);
// 计算分配方案数量
int result = combination(n-1, m-1);
printf('分配方案的数量为:%d\n', result);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/o7Z4 著作权归作者所有。请勿转载和采集!