///Bis-millah-hir-rahmanir-rahim
///arafat,sylhet engineering college,Bangladesh.
/// **************code for nCr****************
/// expression of nCr or C(n,r) = c(n-1,r) + c(n-1,r-1)
#include<bits/stdc++.h>
using namespace std;
int com(int n, int r)
{
if(n==r) return 1;
if(r==1) return n;
return com(n-1,r) + com(n-1,r-1);
}
int main()
{
int n,c,r;
cin>>n>>r;
c= com(n,r);
cout<<c;
return 0;
}
///arafat,sylhet engineering college,Bangladesh.
/// **************code for nCr****************
/// expression of nCr or C(n,r) = c(n-1,r) + c(n-1,r-1)
#include<bits/stdc++.h>
using namespace std;
int com(int n, int r)
{
if(n==r) return 1;
if(r==1) return n;
return com(n-1,r) + com(n-1,r-1);
}
int main()
{
int n,c,r;
cin>>n>>r;
c= com(n,r);
cout<<c;
return 0;
}
No comments:
Post a Comment