Pagini recente » Cod sursa (job #266084) | Cod sursa (job #404216) | Cod sursa (job #2003229) | Cod sursa (job #385549) | Cod sursa (job #1732270)
#include <stdio.h>
#include <stdlib.h>
int x[101],s1;
int suma(int k, int s)
{
int i;
s1=0;
for (i=1; i<=k; i++)
s1+=x[i];
//printf("%d ",s1);
if (s1<=s && k<=6)
return 1;
else
return 0;
}
void afisare()
{
int i;
for (i=1; i<=6; i++)
printf("%d ",x[i]);
printf("\n");
}
void back(int n, int v[],int s,int k)
{
int i,c=1,ok;
for (i=1; i<=3; i++)
{
x[k]=v[i];
//printf("%d ",x[k]);
if (suma(k,s))
{
if (s1==s && ok==0)
{afisare();
ok=1;
}
else
back(n,v,s,k+1);
}
}
}
int main()
{
FILE *pf,*pg;
pf=fopen("loto.in","r");
pg=fopen("loto.out","w");
int n,s;
fscanf(pf,"%d %d",&n,&s);
int v[n+1],i;
for (i=1; i<=n; i++)
fscanf(pf,"%d",&v[i]);
back(n,v,s,1);
return 0;
}