fork download
  1. #include<stdio.h>
  2. int factorial(int n);
  3. void main()
  4. {
  5. int n,r,nPr,nCr,d,e,f;
  6. printf("Enter the value of n and then r\n\n");
  7.  
  8. int factorial(int n);
  9. scanf("%d%d",&n,&r);
  10. if(n<r){
  11. printf("Invalid input\n");
  12. }
  13. else{
  14. d=factorial(n);
  15. e=factorial(r);
  16. f=factorial(n-r);
  17. nPr=d/f;
  18. nCr=d/(e*f);
  19. printf("\n%dP%d=%d\n\n%dC%d=%d\n",n,r,nPr,n,r,nCr);
  20. }
  21.  
  22. }
  23. int factorial(int n)
  24. {
  25. if (n<=1)
  26. return (1);
  27. else
  28. return(n*factorial(n-1));
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
Runtime error #stdin #stdout 0.23s 2172KB
stdin
Standard input is empty
stdout
Standard output is empty