How do I print an array in the form of rows and columns?

Asked

Viewed 35 times

-1

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

int main(){

    int m[3][2];

    for(int i=0; i<3; i++){
        for(int j=0; j<2; j++){
            printf("Digite o elemento na linha e coluna [%d],[%d]: ", i, j);
            scanf("%d", &m[i][j]);
        }
    }

    printf("a matriz e:\n");
    for(int i=0; i<3; i++){
        for(int j=0; j<2; j++){
            printf("%d", m[i][j]);
        }
    }

    return 0;
}
  • 1

    already tried a printf(" n") no for more external?

  • @Bernardolopes got here vlw!

1 answer

4


for(int i=0; i<3; i++){
  for(int j=0; j<2; j++){
    printf("%d", m[i][j]);
  }
  printf("\n");
}

just insert a "printf(" n");" between the two loops for there to be a line break between the matrix lines

Browser other questions tagged

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