VOOZH about

URL: https://www.geeksforgeeks.org/c/cpp-program-to-print-hollow-star-pyramid-diamond-shape-pattern/

⇱ C++ Program To Print Hollow Star Pyramid Diamond Shape Pattern - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C++ Program To Print Hollow Star Pyramid Diamond Shape Pattern

Last Updated : 10 Aug, 2022

Here, we will build a C++ program to print the hollow star pyramid diamond shape pattern that can be achieved with two approaches i.e.

  1. Using  for Loop
  2. Using while loop

Input:

n = 5

Output:

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

1. Using for loop


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

Time complexity: O(n2) for given input n

Auxiliary Space: O(1)

2. Using while loop:


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

Time complexity: O(rows*columns) 

Auxiliary Space: O(1)

Comment