so I’m confused about how to solve this problem in C. The answer to this question is more likely solve if I can understand the logic. But it seems I cant understand it. Sorry if the question title does not matches the explanation of the problem. So:
In C, loop with using for like this, for(x=0;x<10;x++)
, this will result to loop simultaneously without a break.
For example:
for(x=0;x<10;x++)
printf("this is x = %d",x);
result example:
this is x = 0
this is x = 1
.
.
this is x = 10
So how to loop, but will break in each new number and start over then break/pause until new numbers and so on. For example:
for(x=0;x<//variables;x++)
printf("this is x = %d",x);
result:
(start)
this is x = 0
this is x = 1
(over/break)
(start)
this is x = 0
this is x = 1
this is x = 2
(over/break)
(start)
this is x = 0
this is x = 1
this is x = 2
this is x = 3
(over/break)
.
.
.
(start)
this is x = 0
this is x = 1
this is x = 2
this is x = 3
.
.
.
this is x = 10
(over/break)
So how to do this? This maybe seems simple but I can’t find the solution. I hope the explanation can make the problem clear. Thank you.
>Solution :
Just us 2 for loops instead of 1:
for (y = 0; y < 10; y++)
for (x = 0; x < y; x++)
printf("this is x = %d",x);
If you wan’t to change the maximum number, just change the value in the condition of the first loop (y < 10).