Thursday, April 7, 2016

Code for nCr

///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;
}

No comments:

Post a Comment

Speedup Android Studio

Go to Help ->Edit Custom VM Options, and chnge this 4 setting. After that close your Android Studio. This settings are for 8gb of ram pc...