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