fork download
  1. #include <stdio.h>
  2.  
  3. int factorial(int x)
  4. {
  5. int i, result;
  6. result = 1;
  7. for( i = x; i > 1; i-- ) {
  8. result *= i;}
  9. return result;
  10. }
  11.  
  12. int comb(int m, int k){
  13. int s;
  14. s=factorial(m)/(factorial(k)*factorial(m-k));
  15. return s;
  16.  
  17. }
  18. int main(void)
  19. {
  20. int a,p,q;
  21. printf("全体の数(12以下)といくつ取り出すか入力してください");
  22. scanf("%d",&p);
  23. scanf("%d",&q);
  24. a=comb(p,q);
  25. printf("%d",a);
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 5288KB
stdin
10 2
stdout
全体の数(12以下)といくつ取り出すか入力してください45