fork download
  1. //完成しています
  2. #include <stdio.h>
  3.  
  4. int factorial(int n);
  5.  
  6. int comb(int m, int k);
  7.  
  8. int main(void){
  9. int m,k,result;
  10.  
  11. scanf("%d%d",&m,&k);
  12. result=comb(m,k);
  13. printf("%d個の中から%d個を取り出す組み合わせ数は、%d通りです。",m,k,result);
  14. return 0;
  15. }
  16.  
  17. //階乗をする関数
  18. int factorial(int n){
  19. int i,result=1;
  20.  
  21. for( i=n; i>1; i--) result*=i;
  22. return result;
  23. }
  24.  
  25. //組み合わせの数を計算する関数
  26. int comb(int m, int k){
  27. int result;
  28.  
  29. result=factorial(m)/(factorial(k)*factorial(m-k));
  30. return result;
  31. }
Success #stdin #stdout 0s 5284KB
stdin
10 4
stdout
10個の中から4個を取り出す組み合わせ数は、210通りです。