Program to print the Ladder Pattern
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++
// C++ program to print the ladder pattern #include <iostream> using namespace std; // Function to print the desired ladder Pattern void 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 Code int main() { // Size of the Pattern int N = 3; // Print the ladder ladder_pattern(N); return 0; } |
chevron_right
filter_none
Java
// Java program to print the ladder pattern class GFG { // Function to print the desired ladder Pattern static 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 Code public 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 |
chevron_right
filter_none
Python3
# Python3 program to print the ladder pattern # Function to print the desired ladder Pattern def 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 Code if __name__ == "__main__" : # Size of the Pattern N = 3; # Print the ladder ladder_pattern(N); # This code is contributed by AnkitRai01 |
chevron_right
filter_none
C#
// C# program to print the ladder pattern using System; class GFG { // Function to print the desired ladder Pattern static 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 Code static public void Main () { // Size of the Pattern int N = 3; // Print the ladder ladder_pattern(N); } } // This code is contributed by ajit. |
chevron_right
filter_none
Output:
* * * * ***** * * * * ***** * * * * ***** * * * *
Recommended Posts:
- Program to print the pattern ‘D’
- Program to print the given H Pattern
- Program to print the pattern "GFG"
- Program to print the pattern 'G'
- Program to print the given Z Pattern
- Program to print pattern
- Program to print V and inverted-V pattern
- Program to print numeric pattern | Set - 2
- Program to print Crown Pattern
- Program to print a rectangle pattern
- Program to print pyramid pattern
- Program to print Hut Star pattern
- Program to print the Zigzag pattern
- Program to print numeric pattern
- Program to print Step Pattern
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



