Search This Blog

Tuesday, 18 March 2014

finding nCr in C++

/*
  Here nCr stands for combination of all r in n.
  nCr = n! / r! (n-r)!
*/


#include<iostream.h>
#include<conio.h>

int fact(int a)
{
  if(a>1)
  return a*fact(a-1);
  else
  return a;
}

void main()
{
  int n,r;
  float comb;
  cout<<"Enter n and r for nCr : ";
  cin>>n>>r;
  comb=(fact(n)/(fact(r)*fact(n-r)));
  cout<<"Combination of ur values is : "<<comb;
  getch();
}

Output



No comments:

Popular Posts