Pagini recente » Cod sursa (job #2715751) | Cod sursa (job #2958961) | Cod sursa (job #3244310) | Cod sursa (job #1265936) | Cod sursa (job #336532)
Cod sursa(job #336532)
#include <stdio.h>
int main()
{
freopen("combinari.in","r",stdin);
freopen("combinari.out","w",stdout);
int i,n,p,k,st[16];
bool ok;
scanf("%d%d",&n,&p);
k=1;
st[1] = 0;
while (k>0)
{
if (st[k]<n && k <= p)
{
st[k]++;
ok = true;
if(ok)
{
if (k==p)
{
for (i=1;i<=p;i++)
{
printf("%d ",st[i]);
}
printf("\n");
}
else
{
k++;
st[k] = st[k-1];
}
}
}
else
{
k--;
}
}
return 0;
}