Program:
#include<stdio.h>
int main() {
/* c taken for columns */
int i, j, c = 9, m, k;
for (i = 1; i <= 5; i++) {
/* k is used for spaces */
for (k = 1; k <= c; k++) {
printf(" ");
}
for (j = 1; j <= i; j++) { printf("%2d", j); } for (m = j - 2; m > 0; m--) {
/* %2d ensures that the number
* is printed in two spaces
* for alignment */
printf("%2d", m);
}
printf("\n");
/* c is decremented by 2 */
c = c - 2;
}
return 0;
}
Output:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1