Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define assertdomjudge(x) if(!(x)){std::cout<<"ERROR"<<std::endl;}
- using namespace std;
- int calcularResta(int x, int y){
- int resta;
- resta = x -y;
- return resta;
- }
- int calcularFactorial(int x){
- if(x > 1){
- return x * calcularFactorial(x-1);
- }else{
- return 1;
- }
- }
- int calcularCombinacion(int x, int y, int z){
- int combinacion;
- combinacion = x / (y * z);
- return combinacion;
- }
- int main()
- {
- int n, r, resta, combinacion;
- do
- {
- cin >> n >> r;
- if(n < 0){
- return 0;
- }
- else if(r > n){
- cout<<"ERROR"<<endl;
- }else{
- resta = calcularResta(n, r);
- n = calcularFactorial(n);
- r = calcularFactorial(r);
- resta = calcularFactorial(resta);
- combinacion = calcularCombinacion(n, r, resta);
- cout << combinacion << endl;
- }
- }while(n >= 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement