fork download
  1. #include <stdio.h>
  2.  
  3. int comb(int n, int r){
  4. int i, j=0, ans=1;
  5. for(i=0;i<r;i++){
  6. j=n-i;
  7. ans=ans*j;
  8. }
  9. for(i=0;i<r;i++){
  10. j=r-i;
  11. ans=ans/j;
  12. }
  13. return ans;
  14. }
  15. int main(void) {
  16. printf("%d\n", comb(5,2));
  17. printf("%d\n", comb(6,3));
  18. printf("%d\n", comb(7,4));
  19.  
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
10
20
35