DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Combinari

11.19.2008
| 2309 views |
  • submit to reddit
        // 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;
}


    
    Tags:
  • C