I'm trying to generate every possible 3-digit combination like: 012, 013 ,014...
BUT: I want to ignore repeated characters (like 999 or 022) and I also don't want to re-use numbers (if 123 already there, don't display 321) so, the last value should be 789.
Here My code :
int main()
{
int i;
int j;
for(i=1;i<(1<<9);i++)
{
for(j=0;j<9;j++)
{
if ((1<<j)&i) printf("%d\n",j+1);
}
}
}
I want my result to be ordered like:
012, 013, 014, 015, 016, 017, 018, 019, 023, ..., 789
Also, I'm not supposed to use any function but printf / putchar.
I think the easiest way to solve this would be something like
for (i = 0; i <= 7; i++)
{
for (j = i+1; j <= 8; j++)
{
for (k = j+1; k <= 9; k++)
{
printf("%d%d%d\n", i, j, k);
}
}
}