I have an integer array (representing a 4-digit number) that I need to increment so that each integer never goes higher than 3. Basically, it needs to print every 4-digit number that does not have 4 or higher in it. Here's the output I'm expecting compared to the actual output:
Expected: 0000 0001 0002 0003 0010 0011 0012 0013 0020 0021 0022 .... 3333
Received: 0000 1000 2000 3000 3100 3200 3300 3310 3320 3330 3331 3332
I know my algorithm's messed up but I don't know what to do to it:
int i, c[4];
memset(c, 0, sizeof(c));
i = 0;
while (1) {
testprint(c);
c[i]++;
if (c[i] == 3)
i++;
if (i == 3)
break;
}
All testprint does is display every digit in the array. So how should I change my code to correctly increment the array? And do I even need to use an array? How would I do this without one?
4's ... are you sure that is your real output?4s, it was from a previous version...