Category: Blog

Your blog category

  • Full hourglass pattern of Alphabets in C

    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

    #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