Cod sursa(job #505784)

Utilizator sunt_emoSunt emo sunt_emo Data 3 decembrie 2010 23:07:50
Problema Combinari Scor 100
Compilator c Status done
Runda Arhiva educationala Marime 0.41 kb
#include <stdio.h>

int main () {
	short n,k,i=1,j,a[20];
	freopen ("combinari.in","r",stdin);
	freopen ("combinari.out","w",stdout);
	scanf ("%hd%hd",&n,&k);
	a[1]=0;
	while (i) {
		if (i>k) {
			for (j=1; j<=k; j++) printf ("%hd ",a[j]);
			printf ("\n");
			i--;
		}
		else {
			j=a[i]+1;
			if (j>n) {
				i--;
			}
			else {
				a[i]=j;
				i++;
				a[i]=j;
			}
		}
	}
	return 0;
}