VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-print-double-sided-stair-case-pattern/

⇱ Program to print double sided Stair-Case Pattern - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to print double sided Stair-Case Pattern

Last Updated : 3 Jan, 2024

Creating a double-sided staircase pattern is a fun and educational exercise that helps practice programming skills, especially loops and conditional statements. In this article, we will walk through the process of writing a program to print a double-sided stair-case pattern

Examples:

Input: 10
Output:


👁 stardrawio
Output for Input: 10


Approach: To solve the problem follow the below idea:

It uses two nested loops: the outer loop iterates from 1 to n, and the inner loops handle space and star printing based on the row number and the condition of odd or even. If a row number is odd, it increments the value of k by 1; otherwise, it keeps it the same. The space and star printing is adjusted accordingly. The output is a staircase-like pattern of stars and spaces.

Below is the implementation of the above approach:


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

Time Complexity: O(N2)
Auxiliary Space: O(1)

Comment