#include<iostream>
using namespace std;
int fact(int n){
int fac=1;
for(int i=1;i<=n;i++){
fac=fac*i;
}
return fac;
}
int main(){
int n,r;
cout<<"Input n :"<<endl;
cin>>n;
cout<<"Input r :"<<endl;
cin>>r;
int nCr;
cout<<"The nCr value is :"<<endl;
nCr=fact(n)/(fact(n-r)*fact(r));
cout<<nCr<<endl;
return 0;
}
Input : n = 5, r = 2
Output : 10
The value of 5C2 is 10
Input : n = 3, r = 1
Output : 3
Code Example |
---|
Cpp :: Frequency of a substring in a string C++ |
Cpp :: sort using lambda c++ |
Cpp :: c++ call by value vs call by reference |
Cpp :: how to get length of a file in c++ |
Cpp :: c++ count number of element in vector |
Cpp :: c++ 20 struct initialization |
Cpp :: iterate over map c++17 |
Cpp :: iteraate through a vector |
Cpp :: sleep system function linux c++ |
Cpp :: c++ reading string |
Cpp :: if vector is empty c++ |
Cpp :: doubly linked list c++ code |
Cpp :: c++ init multidimensional vector |
Cpp :: armstrong number in cpp |
Cpp :: header file for unordered_map in c++ |
Cpp :: iterate over 2 vectors c++ |
Cpp :: round double to 2 decimal places c++ |
Cpp :: c++ clear char array |
Cpp :: swapping of two numbers |
Cpp :: c++ call by reference |
Cpp :: cpp vector2 |
Cpp :: for loop c++ |
Cpp :: c++ print binary treenode |
Cpp :: c++ casting |
Cpp :: how to print a text in c++ |
Cpp :: input cpp |
Cpp :: #define online judge in cpp |
Cpp :: c include |
Cpp :: creare array con c++ |
Cpp :: double to float c++ |