In this tutorial, we will write a C program to print an hourglass pattern using characters. Before that, you may go through the following topic in C.
Full hourglass pattern of Alphabets 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> void main() { int rows, i, j, k; printf("Enter the no. of rows: "); scanf("%d", &rows); // ASCII value of alphabet 'A' int alphabet = 65; for (i = 0; i <= rows - 1; i++) { for (j = 0; j < i; j++) printf(" "); for (k = i; k <= rows - 1; k++) printf("%c ", (char)(alphabet + k)); printf("\n"); } for (i = rows - 1; i >= 0; i--) { for (j = 0; j < i; j++) printf(" "); for (k = i; k <= rows - 1; k++) printf("%c ", (char)(alphabet + k)); printf("\n"); } getch(); } |
Output:
Enter the no. of rows: 5
A B C D E
B C D E
C D E
D E
E
E
D E
C D E
B C D E
A B C D E