Given a number N denoting the number of rows. The task is to print the zigzag pattern with N rows as shown in the below examples.
Input : 2 Output : 1 2 3 Input : 5 Output : 1 2 6 3 7 10 4 8 11 13 5 9 12 14 15
1. Use a for loop for printing the number of rows.
2. Use two for loops for printing space and pattern.
3. Calculate starting value for each row with variable t.
Below is the implementation of above approach:
1 2 7 3 8 12 4 9 13 16 5 10 14 17 19 6 11 15 18 20 21
- Program to print pyramid pattern
- Program to print hollow pyramid and diamond pattern
- C Program to print pyramid pattern
- Program to print a inverse pyramid character pattern
- Print the following pyramid pattern
- Print the pyramid pattern with given height and minimum number of stars
- Program to print Even Odd Number Pyramid
- Programs for printing pyramid patterns using recursion
- Program to print a pattern of numbers
- Program to print numbers with diamond pattern
- Programs for printing pyramid patterns in Python
- Programs for printing pyramid patterns in C++
- Programs for printing pyramid patterns in Java
- PHP programs for printing pyramid patterns
- Program to print 'N' alphabet using the number pattern from 1 to n
- Program to print the Alphabets of a Given Word using * pattern
- Print pattern using only one loop | Set 1 (Using setw)
- Print the pattern by using one loop | Set 2 (Using Continue Statement)
- Print numbers in matrix diagonal pattern
- Python Program to print digit 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 firstname.lastname@example.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.