fork download
  1. #include <stdio.h>
  2.  
  3. int factorial(int n){
  4. int i, result;
  5. result = 1;
  6. for (i = n; i > 1; i--) {
  7. result *= i;
  8. }
  9. return result;
  10. }
  11. int comb(int m,int k){
  12. return factorial(m)/(factorial(k)*factorial(m-k));
  13.  
  14. }
  15. int main(void) {
  16. int m, k;
  17. scanf("%d", &m);
  18. scanf("%d", &k);
  19. printf("%d個の中から%d個を取り出す組み合わせの数は%d通りです。\n", m, k, comb(m, k));
  20.  
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 5284KB
stdin
10 3
stdout
10個の中から3個を取り出す組み合わせの数は120通りです。