Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
621 B
1
Indexable
Never
#include <iostream>
using namespace std;

int factorial(int n) {
    if (n <= 1) {
        return 1;
    }
    return n * factorial(n - 1);
}

int nCr(int n, int r) {
    if (r > n) {
        return 0;
    }
    int numerator = factorial(n);
    int denominator = factorial(r) * factorial(n - r);
    return numerator / denominator;
}

int main() {
    int n, r;
    cout << "Enter the value of n: ";
    cin >> n;
    cout << "Enter the value of r: ";
    cin >> r;

    int combinations = nCr(n, r);
    cout << "Number of combinations (nCr) = " << combinations << endl;

    return 0;
}