Reputation: 13
void printSudoku9x9(int grid[9][9]) {
for (int y = 0; y < 9; y++){
for (int x = 0; x < 9; x++)
cout << grid[y][x] <<' ';
cout << endl;
}
}
Upvotes: 0
Views: 210
Reputation: 3402
The usual way is to use the '\b'
escape-character which moves the output cursor back to one character:
void printSudoku9x9(int grid[9][9]) {
for (int y = 0; y < 9; y++){
for (int x = 0; x < 9; x++)
cout << grid[y][x] <<' ';
cout << '\b' << endl;
}
}
Upvotes: 0
Reputation: 104599
Instead of printing a space after each character and dealing with the end, print a space before each character printed except for when (x==0)
.
void printSudoku9x9(int grid[9][9]) {
for (int y = 0; y < 9; y++){
for (int x = 0; x < 9; x++) {
char leading = (x == 0) ? "" : " ";
cout << leading << grid[y][x];
}
cout << endl;
}
}
Upvotes: 2