Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

how to do nCr in c++

#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;
}
 
PREVIOUS NEXT
Tagged: #nCr
ADD COMMENT
Topic
Name
3+4 =