Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int fact(unsigned int n){
- if(n==0){
- return 1;
- }
- if(n==1){
- return 1;
- }
- return fact(n-1) * n;
- }
- int combination(int n, int r){
- return (fact(n) / (fact(r) * fact(n-r) ) );
- }
- int permutation(int n, int r){
- return (fact(n) / (fact(n-r)));
- }
- int main(){
- int n, r;
- cout << "Enter the value of n = ";
- cin >> n;
- cout << "Enter the value of r = ";
- cin >> r;
- cout << "Combination = " << combination(n, r) << endl;
- cout << "Permutation = " << permutation(n, r) << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment