VOOZH about

URL: https://www.geeksforgeeks.org/computer-science-fundamentals/program-to-print-pyramid-pattern/

⇱ Program to print pyramid pattern - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to print pyramid pattern

Last Updated : 22 Jun, 2022

Write to program to print the pyramid pattern formed of stars 

Example : 

Input: n = 6
Output:
 *
 * *
 * * *
 * * * *
 * * * * *
 * * * * * * 
 * * * * *
 * * * *
 * * *
 * * 
 *


We strongly recommend you to minimize your browser and try this yourself first.
The idea is to use two for loops for every part of the pyramid. The two parts may be classified as upper part and lower part 

Output : 

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

Time complexity: O(n2)

Auxiliary Space: O(1)
 

Comment