I am trying to work on a program where the user enters a random number and the program enters a list from 0 to 9.
For example, say that the user enters the number 12 then the screen should look like this:
0123456789012
Where ‘2’ at the end indicates the 12th number. I’ve tried this but it gives me an infinite loop and I don’t know how to tell it to stop:
for(i = 0; i < cells; i++) {
i = i%10;
printf("%d", i);
}
The cells here is the number that the user enters.
The problem is that you are changing
iin the loop. You must iterate as many times as the input. You’re almost there, but you loop forever because you are modifyingiin such a way that it will never be larger than or equal tocellsforcells > 10.Try this:
Also…
The second
2is the 13th number, not the 12th 🙂