Doubts in solving an exercise using while or for [closed]

-4

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:

  • 123
  • 456
  • 789
  • ...
  • Thank you very much for your attention. Att,

        
    asked by anonymous 25.05.2016 / 02:43

    1 answer

    3

    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;
    }
    
        
    25.05.2016 / 03:28