ad

Friday, April 11, 2025

C Program to print Hourglass Pattern

  C Program

C Program to print Hourglass Pattern


C Program to print Hourglass Pattern

Example

#include <stdio.h>
 
int main()
{
  int i, j, k, rows;
 
  printf("Enter the no. of rows: ");
  scanf("%d", &rows);
 
  printf("Output: \n\n");
 
  for (i = 1; i <= rows; i++)
  {
    for (k = 1; k < i; k++)
      printf(" ");
 
    for (j = i; j <= rows; j++)
      printf("* ");
 
    printf("\n");
  }
 
  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;
}

C Program to print Hourglass Pattern

Output 

C Program to print Hourglass Pattern


Related Post :-

C program to print pascals triangle

C program to print inverted half

Print Inverted Half Pyramid of Stars Pattern

No comments:

Post a Comment