Program to print the Ladder Pattern

27 Apr, 2021
Given an integer N, the task is to print the ladder with N steps using ‘*’. The ladder will be with the gap of 3 spaces between two side rails. 
Input: N = 3
Output: 
*   *
*   *
*****
*   *
*   *
*****
*   *
*   *
*****
*   *
*   *

Input: N = 4
Output: 
*   *
*   *
*****
*   *
*   *
*****
*   *
*   *
*****
*   *
*   *
*****
*   *
*   *
 
Approach: Dividing the pattern into two sub-pattern.  
 
*    *
*    *
which will be printed N+1 times
 
*****
*    *
*    *
which will be printed N times.
Below is the implementation of the above approach: 
C++
Java
Python3
C#
Javascript
// C++ program to print the ladder pattern #include <iostream>using namespace std; // Function to print the desired ladder Patternvoid ladder_pattern(int N){     for (int i = 0; i <= N; i++) {        // Printing the sub-pattern 1        // N+1 times        cout << "*   *" << endl;        cout << "*   *" << endl;         if (i < N) {            // Printing the sub-pattern 2            // N times            cout << "*****" << endl;        }    }} // Driver Codeint main(){    // Size of the Pattern    int N = 3;     // Print the ladder    ladder_pattern(N);     return 0;}
// Java program to print the ladder patternclass GFG{ // Function to print the desired ladder Patternstatic void ladder_pattern(int N){     for (int i = 0; i <= N; i++)    {                 // Printing the sub-pattern 1        // N+1 times        System.out.println("*   *");        System.out.println("*   *");         if (i < N)        {            // Printing the sub-pattern 2            // N times            System.out.println("*****" );        }    }} // Driver Codepublic static void main(String args[]){    // Size of the Pattern    int N = 3;     // Print the ladder    ladder_pattern(N);}} // This code is contributed by Rajput Ji
# Python3 program to print the ladder pattern # Function to print the desired ladder Patterndef ladder_pattern(N) :     for i in range(N + 1) :                 # Printing the sub-pattern 1        # N + 1 times        print("*   *");        print("*   *");         if (i < N) :                         # Printing the sub-pattern 2            # N times            print("*****"); # Driver Codeif __name__ == "__main__" :         # Size of the Pattern    N = 3;     # Print the ladder    ladder_pattern(N);     # This code is contributed by AnkitRai01
// C# program to print the ladder patternusing System; class GFG{     // Function to print the desired ladder Patternstatic void ladder_pattern(int N){    for (int i = 0; i <= N; i++)    {                 // Printing the sub-pattern 1        // N+1 times        Console.WriteLine("*   *");        Console.WriteLine("*   *");         if (i < N)        {            // Printing the sub-pattern 2            // N times            Console.WriteLine("*****");        }    }} // Driver Codestatic public void Main (){    // Size of the Pattern    int N = 3;     // Print the ladder    ladder_pattern(N);}} // This code is contributed by ajit.
<script>      // JavaScript program to print the ladder pattern       // Function to print the desired ladder Pattern      function ladder_pattern(N) {        for (var i = 0; i <= N; i++) {          // Printing the sub-pattern 1          // N+1 times          document.write("*      *" + "<br>");          document.write("*      *" + "<br>");           if (i < N) {            // Printing the sub-pattern 2            // N times            document.write("*****" + "<br>");          }        }      }       // Driver Code      // Size of the Pattern      var N = 3;      // Print the ladder      ladder_pattern(N);    </script>
*   *
*   *
*****
*   *
*   *
*****
*   *
*   *
*****
*   *
*   *
 
ankthon
Rajput-Ji
jit_t
rdtank
pattern-printing
School Programming
pattern-printing
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.