numbers - 3 digit generator in C -


i'm trying generate every possible 3-digit combination like: 012, 013 ,014...

but: want ignore repeated characters (like 999 or 022) , don't want re-use numbers (if 123 there, don't display 321) so, last value should 789.

here 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 result ordered like:

012, 013, 014, 015, 016, 017, 018, 019, 023, ..., 789 

also, i'm not supposed use function but printf / putchar.

i think easiest way solve like

for (i = 0; <= 7; i++) {     (j = i+1; j <= 8; j++)     {         (k = j+1; k <= 9; k++)         {             printf("%d%d%d\n", i, j, k);         }     } } 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -