fork(1) download
  1. #include <stdio.h>
  2.  
  3.  
  4. int kaijo(int n) {
  5. int i, result = 1;
  6. for(i = 1; i <= n; i++) {
  7. result *= i;
  8. }
  9. return result;
  10. }
  11.  
  12.  
  13. int comb(int m, int k) {
  14. return kaijo(m) / (kaijo(k) * kaijo(m - k));
  15. }
  16.  
  17. int main() {
  18. int m, k;
  19.  
  20. scanf("%d", &m);
  21. printf("mを入力してください:%d\n",m);
  22.  
  23.  
  24. scanf("%d", &k);
  25. printf("kを入力してください:%d\n",k);
  26.  
  27. printf("%d個の中から%d個を取り出す組合せ数は、%d通りです。\n", m, k, comb(m, k));
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5288KB
stdin
5
3
stdout
mを入力してください:5
kを入力してください:3
5個の中から3個を取り出す組合せ数は、10通りです。