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