C++ Programming Code Examples C++ > Sorting Searching Code Examples Program to Compute Combinations using Factorials Program to Compute Combinations using Factorials - This algorithm prints a total number of combination possible for given n and r value. - The time complexity of this algorithm is O(n). - This algorithm takes the input of n and r value. - Print the result using ( n! / (r! * (n-r)!)). - Exit. #include<iostream> using namespace std; // A function to find the factorial. int factorial(int n) { int i; for(i = n-1; i > 1; i--) n *= i; return n; } int main() { int n, r, result; cout<<"A program to find combination from nCr format using ( n! / (r! * (n-r)!))"; cout<<"\n\n\tEnter the value of n: "; cin>>n; cout<<"\tEnter the value of r: "; cin>>r; // Get result using formula to calculate combinations. result = factorial(n)/(factorial(r)*factorial(n-r)); cout<<"\nThe number of possible combinations is: "<<result; }