Cod sursa(job #598708)

Utilizator dspMihaiDespotovici Mihai dspMihai Data 26 iunie 2011 19:45:03
Problema Submultimi Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <stdio.h>
#define Nmax 17
int n,str[Nmax],ok;

int back (int x)
{
	long i,l;
	l=x;
	if (x==n+1)
	{
		ok=0;
		for(i=1; i<=n && !ok; i++)
			if (str[i]) ok=1;
		if (ok)
		{
		for(i=1; i<=n; i++)
			if (str[i]) printf("%d ", i);
		printf("\n");
		}
	}
	else for (i=0; i<=1; i++)
	{
		str[l]=i;
		back(l+1);
	}
}
int main ()
{
	freopen("submultimi.in", "r",stdin);
	freopen("submultimi.out", "w",stdout);
	scanf("%d", &n);
	back(1);
	return 0;
}