Good evening my dear, My question is about repetition (while and for). In an exercise I want to print the numbers from one to 10. But I want to group them 2 by 2 or 3 by 3 to follow this logic:
Thank you very much for your attention. Att,
Good evening my dear, My question is about repetition (while and for). In an exercise I want to print the numbers from one to 10. But I want to group them 2 by 2 or 3 by 3 to follow this logic:
Thank you very much for your attention. Att,
Hello, your question is not so clear, try to present a piece of code you have.
Here is an algorithm that solves the question (according to what I understand of your question) grouping it by 2, and when it arrives at 10 it restarts the count:
#include<stdio.h>
int main(void)
{
int i = 0, j = 0, aux = 1;
for (i = 1; i <= 10; i++){
printf("%d. ", i);
for (j = aux; j <= (aux + 1); j++){
printf("%d ", j);
}
aux = j;
if(aux > 9) aux = 1;
printf("\n");
}
return 0;
}