fork download
  1. #include <stdio.h>
  2. //まず
  3. int factorial(int n) {
  4. int result = 1;
  5. for(int i = 1; i <= n; i++) {
  6. result *= i;
  7. }
  8. return result;
  9. }
  10.  
  11. //次に
  12. int comb(int m, int k) {
  13. return factorial(m) / (factorial(k) * factorial(m - k));
  14. }
  15. int main(void) {
  16. int m, k;
  17. scanf("%d", &m);
  18. scanf("%d", &k);
  19.  
  20. if(m < k) {
  21. printf("エラー\n");
  22. } else if(m > 12) {
  23. printf("エラー\n");
  24. } else {
  25. int combination = comb(m, k);
  26. printf("%d個の中から%d個を取り出す組合せ数は、%d通りです。\n", m, k, combination);
  27. }
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5280KB
stdin
10 3
stdout
10個の中から3個を取り出す組合せ数は、120通りです。