Advertisement
Abelsor

S4_Ejercicio_3

Mar 1st, 2023 (edited)
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. unsigned long combinaciones(int, int);
  5. unsigned long factorial(int);//usar long long para no desborde tan rapido
  6.  
  7. int main(){
  8.   int opcion,n,m;
  9.     //ESTA OPCION SIRVE PARA EVALUAR DE FORMA INDEPENDIENTE LAS 2 funciones requeridas
  10.     cin>>opcion;
  11.     cin >>n;
  12.     if(opcion==1){//SECCION QUE EVALUA LA FUNCION Factorial
  13.         cout<<factorial(n);
  14.     }else{
  15.         if(opcion==2){//SECCION QUE EVALUA LA FUNCION combinacion
  16.             cin>>m;
  17.             cout<<combinaciones(m,n)<<endl;
  18.         }
  19.     }
  20.     return 0;
  21. }
  22.  
  23. unsigned long combinaciones(int m, int n){
  24.     unsigned long comb = factorial(n)/(factorial(m)*factorial(n-m));
  25.     return comb;
  26. }
  27.  
  28. unsigned long factorial(int n){
  29.    
  30.     unsigned long fact=1;
  31.    
  32.     for(int i=1 ; i<=n ; i++){
  33.         fact *= i; 
  34.     }
  35.    
  36.     return fact;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement