Home > Software engineering >  Print each row twice in a 2D array - C
Print each row twice in a 2D array - C

Time:03-27

Good day! How do I print each row twice in a 2D array in C program?

for(int row = 0; row < 5; row  ) {
    for(int col = 0; col < 5; col  ) {
        printf("%d ", arr[row][col]);            
    }
    printf("\n");
}

The above code is my loop for printing the elements that I received from user.

CodePudding user response:

for(int row = 0; row < 5; row  ) {
    for(int col = 0; col < 5; col  ) {
        printf("%d ", arr[row][col]);            
    }
    for(int col = 0; col < 5; col  ) {
        printf("%d ", arr[row][col]);            
    }
    printf("\n");
}

or you want to use only one loop

for(int row = 0; row < 5; row  ) {
    for(int col = 0; col < 5*2; col  ) {
        printf("%d ", arr[row][col%5]);            
    }
    printf("\n");
}
  • Related