Hourglass number Pattern in C

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

#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:

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