Over a million developers have joined DZone.

Combinari

·
// combinari



#include "stdafx.h"


long comb(int n, int k)
{
	long f;
	if ((n==k) || (k==0)) f=1;
	else f = comb(n-1, k-1) + comb(n-1, k);

	return f;
}

int _tmain(void)
{
	int n, k;

	printf("n=");scanf("%d",&n);
	printf("k=");scanf("%d",&k);

	printf( "f=%ld", comb(n, k) );

	return 0;
}


Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}