

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Program to Compute Combinations using Factorials
The following is an example to compute combinations using factorials.
Example
#include <iostream> using namespace std; int fact(int n) { if (n == 0 || n == 1) return 1; else return n * fact(n - 1); } int main() { int n, r, result; cout<<"Enter n : "; cin>>n; cout<<"\nEnter r : "; cin>>r; result = fact(n) / (fact(r) * fact(n-r)); cout << "\nThe result : " << result; return 0; }
Output
Enter n : 10 Enter r : 4 The result : 210
In the above program, the code is present in fact() function to calculate the factorial of numbers.
if (n == 0 || n == 1) return 1; else return n * fact(n - 1);
In the main() function, two numbers of combination are entered by user. Variable ‘result’ is storing the calculated value of combination using factorial.
cout<<"Enter n : "; cin>>n; cout<<"\nEnter r : "; cin>>r; result = fact(n) / (fact(r) * fact(n-r));
- Related Questions & Answers
- C++ Program to Compute Combinations using Recurrence Relation for nCr
- Using BigInt to calculate long factorials in JavaScript
- 8085 Program to compute LCM
- C++ Program to Compute Discrete Fourier Transform Using Naive Approach
- C program to compute geometric progression
- C program to compute linear regression
- C++ Program to Compute the Area of a Triangle Using Determinants
- Find last two digits of sum of N factorials using C++.
- Java program to compute Remainder and Quotient
- C++ Program to Compute DFT Coefficients Directly
- C Program to Compute Quotient and Remainder?
- Program to compute LCM in 8085 Microprocessor
- Program to compute Log n in C
- Python program to compute a Polynomial Equation
- Java Program to Compute Quotient and Remainder
Advertisements