Doubts in the resolution of an exercise using while or for

Asked

Viewed 74 times

-4

Good evening my dear, My doubt relates to repetition (while and for). In one exercise I want to print the numbers from one to 10. However I want to group them 2 to 2, or 3 to 3 to follow that logic:

  1. 123
  2. 456
  3. 789
  4. ...

Thank you very much for your attention. Att,

  • 3

    could [Dit] your post and add what you’ve tried to do so far, so it’s easier to help you :) Hug

  • 3

    It is not clear the problem. If you tried any solution, could post to facilitate

  • not quite specific your question, has how to post what you’ve done to have a clue of what you need, and know how far you’ve come!

1 answer

3

Hello, your doubt is not so clear, try to present a piece of the code you have.

It follows an algorithm that solves the question (according to what I understood of your question) by grouping 2 in 2, and when it arrives in 10 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;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.