VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-print-half-diamond-star-pattern/

⇱ Program to print half Diamond star pattern - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to print half Diamond star pattern

Last Updated : 12 Jul, 2025

Given an integer N, the task is to print half-diamond-star pattern.

*
**
***
****
*****
******
*****
****
***
**
*

Examples:

Input: N = 3
Output:
*
**
***
**
*

Input: N = 6
Output:
*
**
***
****
*****
******
*****
****
***
**
*

Approach: The idea is to break the pattern into two halves that is upper half and lower half. Then print them separately with the help of the loops. The key observation for printing the upper half and lower half is described as below:

  • Upper half: The upper half of the pattern contains star '*' in increasing order where ith line contains following number of star:
Number of '*' in ith line = 
  • Lower Half: The lower half of the pattern contains star '*' in decreasing order where ith line contains following number of star:
Number of '*' in ith line = 

Output
*
**
***
****
*****
****
***
**
*

Time complexity: O(N2) where N is given integer
Auxiliary Space: O(1)

Comment