If you want spaces between the numbers, simply put a space after the %d on lines 8 and 11 of my code, and double the number of spaces printed prior to the row (line 5):
Code:
int x,y;
int rows = 10;
for (y = 1; y <= rows; ++y) {
for (x = y; x < rows; ++x) {
printf(" ");
}
for (x = 0; x < y; ++x) {
printf("%d ",(y+x) % 10);
}
for (x = y - 1; x > 0; --x) {
printf("%d ",(y+x-1) % 10);
}
printf("\n");
}
I still have the shortest code
I could probably make it even shorter if I used the abs() function.
Code:
int x,y;
int rows = 10;
for (y = 1; y <= rows; ++y) {
for (x = y; x < rows; ++x) {
printf(" ");
}
for (x = 1; x < y * 2; ++x) {
printf("%d ",(y + y - abs(x-y) - 1) % 10);
}
printf("\n");
}