Print multiple arrays separately

0

I would like to know if you can print these three arrays without having to create multiple for's , their printing on the screen should be separated. (I need an alternative because I have little space and the code was very extensive when I went to print in the conventional way)

#include <stdio.h>
#include <locale.h>
#include <stdlib.h>

int main () { setlocale(LC_ALL,"Portuguese");

    int mat1[100][100], mat2[100][100], mat3[100][100], linha = 0, coluna = 0;

    // red, blue, green

    printf("\nInforme o número de linhas e colunas: ");
    scanf("%i %i",&linha,&coluna);

    for ( int i = 0; i < linha; i++){
        for ( int h = 0; h < coluna; h++){
            printf("\nInforme um digito para linha %i, coluna %i matriz red: ",i, h);
            scanf("%i",&mat1[i][h]);
        }
        system("cls");
        for ( int j = 0; j < coluna; j++){
            printf("\nInforme um digito para linha %i, coluna %i matriz blue: ",i, j);
            scanf("%i",&mat2[i][j]);
        }
        system("cls");
        for ( int q = 0; q < coluna; q++){
            printf("\nInforme um digito para linha %i, coluna %i matriz green: ",i,q);
            scanf("%i",&mat3[i][q]);
        }
        system("cls");
    }

    // imprimir toda a primeira, depois a segunda e por fim a terceira...

    return 0;
}
    
asked by anonymous 03.10.2016 / 04:47

1 answer

2

If you want to print 3 or more, it's best to put them together.

int matriz[3][100][100];
int x,y,z;
for(x=0; x<3; x++)
    for(y=0; y<100; y++)
        for(z=0; z<100; z++;){
            printf("entre o valor da matriz %x, linha %d, coluna %d: ", z,y,z);
            scanf("%d", &matrz[x][y][z]);
         }

for(x=0; x<3; x++)
    for(y=0; y<100; y++)
        for(z=0; z<100; z++;)
            printf("matriz %d[%d,%d]: %d",x,y,z,matriz[x][y][z]);

The first is by walking matrices (matrices x == total) and the other two run along rows and columns.

So you can go through as many arrays as you want, and leave the code more organized;

    
03.10.2016 / 05:39