#include <stdio.h>
int main() {
int i, space, rows, k = 0, count = 0, count1 = 0,x=0;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
if(x<(rows*2)) x+=2;
for (space = 1; space <= i; ++space) {
printf(" ");
++count;
}
while (k !=x) {
if (count <= rows) {
printf("%d ", i+k);
++count;
} else {
++count1;
printf("%d ", (i + k - 2 * count1));
}
++k;
}
count1 = count = k = 0;
printf("\n");
}
return 0;
}
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).