Number Pyramid
C
Easy
6 views
Problem Description
1
121
12321
1234321
123454321 Logic: Spaces, increasing numbers, then decreasing. Symmetry should be maintained.
Official Solution
#include <stdio.h>
int main(void)
{
int n = 5; /* number of rows */
for (int i = 1; i <= n; i++) {
/* Print leading spaces */
for (int s = 1; s <= n - i; s++) {
printf(" ");
}
/* Print increasing numbers */
for (int num = 1; num <= i; num++) {
printf("%d", num);
}
/* Print decreasing numbers */
for (int num = i - 1; num >= 1; num--) {
printf("%d", num);
}
printf("n");
}
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!