compinations

amatallah 0 Tallied Votes 139 Views Share

this small function calculate mCr

//recurtion fun. to calculate  nCr
#include <iostream.h>
#include <conio.h>   //for getch(),clrscr()
/******************** recurtion  fun. *************************************/
long c(int n,int r)    //fun.calculate the combination to 2num
{
	if ((n==r)||(r==0))
		return 1;
	return (c(n-1,r-1)+c(n-1,r));
}
/***************************** main prog ***********************************/
void main()
{
	clrscr();
	int x,y;
	cout<<" Enter The Two Numbers";
	cin>>x>>y;
	if ((x<y)||(x<=0))
	{
		cout<<" error try agin n1>n2 & n1>0 :" ;
                cin>>x>>y;
		getch();
	}
	cout<<c(x,y);
	getche();
}
manutd 2 Junior Poster

This void main() should be int main(void) . Try to find alternatives to using clrscr, etc, as they are non-portable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.