I'm trying to do something like this
But I can't think of something to do it to a generic number. See, I got the maximum space the number can fit in (in this case, the length is 4). But the numbers inside it can have any length less than or equal to (space - 2) so it could fit without touching the borders. I need to center the number in each square no matter how many characters it has.
I tried something like this for the first row:
printf(" ");
for (i = 0; i < columns; i++) {
printf(" ");
printf("%*d", length, i);
printf(" ");
}
But it wouldn't align the number in the center, but on right. What should I do?