Advertisement
Guest User

CombinacionesRecursivos

a guest
Feb 24th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #define assertdomjudge(x) if(!(x)){std::cout<<"ERROR"<<std::endl;}
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int calcularResta(int x, int y){
  8. int resta;
  9. resta = x -y;
  10. return resta;
  11. }
  12.  
  13. int calcularFactorial(int x){
  14. if(x > 1){
  15. return x * calcularFactorial(x-1);
  16. }else{
  17. return 1;
  18. }
  19. }
  20.  
  21. int calcularCombinacion(int x, int y, int z){
  22. int combinacion;
  23. combinacion = x / (y * z);
  24. return combinacion;
  25. }
  26.  
  27.  
  28. int main()
  29. {
  30. int n, r, resta, combinacion;
  31. do
  32. {
  33. cin >> n >> r;
  34. if(n < 0){
  35. return 0;
  36. }
  37. else if(r > n){
  38. cout<<"ERROR"<<endl;
  39. }else{
  40. resta = calcularResta(n, r);
  41. n = calcularFactorial(n);
  42. r = calcularFactorial(r);
  43. resta = calcularFactorial(resta);
  44. combinacion = calcularCombinacion(n, r, resta);
  45. cout << combinacion << endl;
  46. }
  47.  
  48. }while(n >= 0);
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement