In this tutorial, we will write a C program to print Full sandglass star patterns. Before that, you may go through the following topic in C.
The program below takes a user input for the number of rows needed and then in decreasing order of the upper half is printed and then increasing the order, the second half sandglass is printed.
This is a full hourglass pattern program in C or you can say full sandglass pattern program using a star.
Full Hourglass 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 34 35 36 | #include <stdio.h> int main() { int i, j, k, rows; printf("Enter the no. of rows: "); scanf("%d", &rows); printf("Output: \n\n"); //upper half for (i = 1; i <= rows; i++) { for (k = 1; k < i; k++) printf(" "); for (j = i; j <= rows; j++) printf("* "); printf("\n"); } //lower half for (i = rows - 1; i >= 1; i--) { for (k = 1; k < i; k++) printf(" "); for (j = i; j <= rows; j++) printf("* "); printf("\n"); } return 0; } |
Output:
1 2 3 4 5 6 7 8 9 10 11 | Enter the number of rows: 5 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |