Untitled
unknown
plain_text
2 years ago
621 B
5
Indexable
#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; }
Editor is loading...