In this tutorial, we will write a C Program to display full hourglass patterns using numbers. Before that, you may go through the following topic in C.
Hourglass number Pattern in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <stdio.h> int main() { int i, j, rows; printf("Enter the number of rows: "); scanf("%d", &rows); for (i = 1; i <= rows; i++) { for (int j = 1; j < i; j++) printf(" "); for (j = i; j <= rows; j++) printf("%d ", j); printf("\n"); } for (i = rows - 1; i >= 1; i--) { for (j = 1; j < i; j++) printf(" "); for (j = i; j <= rows; j++) printf("%d ", j); printf("\n"); } return 0; } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 | Enter the number of rows: 6 1 2 3 4 5 6 2 3 4 5 6 3 4 5 6 4 5 6 5 6 6 5 6 4 5 6 3 4 5 6 2 3 4 5 6 1 2 3 4 5 6 |