Open In App

Program to print pyramid pattern

Last Updated : 22 Jun, 2022
Comments
Improve
Suggest changes
6 Likes
Like
Report

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 

C++
C Java Python3 C# PHP JavaScript

Output : 

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

Time complexity: O(n2)

Auxiliary Space: O(1)
 


Java Program to Print Star Pattern in Triangle Shape

Similar Reads