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