Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- unsigned long combinaciones(int, int);
- unsigned long factorial(int);//usar long long para no desborde tan rapido
- int main(){
- int opcion,n,m;
- //ESTA OPCION SIRVE PARA EVALUAR DE FORMA INDEPENDIENTE LAS 2 funciones requeridas
- cin>>opcion;
- cin >>n;
- if(opcion==1){//SECCION QUE EVALUA LA FUNCION Factorial
- cout<<factorial(n);
- }else{
- if(opcion==2){//SECCION QUE EVALUA LA FUNCION combinacion
- cin>>m;
- cout<<combinaciones(m,n)<<endl;
- }
- }
- return 0;
- }
- unsigned long combinaciones(int m, int n){
- unsigned long comb = factorial(n)/(factorial(m)*factorial(n-m));
- return comb;
- }
- unsigned long factorial(int n){
- unsigned long fact=1;
- for(int i=1 ; i<=n ; i++){
- fact *= i;
- }
- return fact;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement