The following code is for printing the elements of a matrix in spiral order. The program works fine. The problem, however, is that the online compiler against which I\'m checkin
An answer after accepted answer:
Rather than:
while (k < m && l < n) {
...
printf("%d ", a[k][i]);
...
printf("%d ", a[i][n-1]);
...
printf("%d ", a[m-1][i]);
...
printf("%d ", a[i][l]);
...
}
Change the format.
const char *format = "%d";
while (k < m && l < n) {
...
printf(format, a[k][i]);
format = " %d";
...
printf(format, a[i][n-1]);
...
printf(format, a[m-1][i]);
...
printf(format, a[i][l]);
...
}
fputc('\n', stdout); // if desired.