how do i print out a 2 dimensional grid in a grid form in c
when i do:
int n = 3;
for ( x = 0; x %26lt; n; x++){
for (y = 0, y %26lt; n, y++){
printf(" %d ", A[i][j]);
}
}
it prints out everything in a list like 3 3 3 3 3 3 3 3 3 3
______________________________________...
I want it to have it print out in a grid like
3 3 3
3 3 3
3 3 3
Can anyone help me?
Print 2 dimensional grid in C?
You need to return the carriage after the first loop is done:
for ( x = 0; x %26lt; n; x++){
for (y = 0, y %26lt; n, y++){
printf(" %d ", A[i][j]);
}
printf ("\n"); /* THIS LINE */
}
Reply:int n = 3;
for ( x = 0; x %26lt; n; x++){
for (y = 0, y %26lt; n, y++){
printf(" %d ", A[i][j]);
}
// at this point new line character
printf( "\n);
//here is the point where you can operate as row type
}
Reply:This should do it:
int n = 3;
for ( x = 0; x %26lt; n; x++)
{
for (y = 0, y %26lt; n, y++)
{
printf(" %d ", A[i][j]);
}
printf( "\n); /* for the next row of x */
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment