We have to print natural numbers columns wise with decreasing size, depending upon given number of lines as described in the examples below –
Input : 5 Output : 1 2 6 3 7 10 4 8 11 13 5 9 12 14 15 Input : 3 Output : 1 2 4 3 5 6
- We will take outer for loop, which is for how many lines we want to print.
- Since we want to print natural number column by column, for this we will take an inner for loop.
In the above example the number of element is depending upon number for i, therefore we take a variable k which is equal to i
Value of i || Number of Element 1 || 1 2 || 2 3 || 3 so on
- Using the logic k = k + n – j, we will get natural numbers according to requirement.
1 2 6 3 7 10 4 8 11 13 5 9 12 14 15
- C++ program to print all Even and Odd numbers from 1 to N
- Program to print first n Fibonacci Numbers | Set 1
- Program to print a pattern of numbers
- Python program to print even numbers in a list
- Program to print numbers with diamond pattern
- Python program to print odd numbers in a List
- Python Program to Print Numbers in an Interval
- Program to print all the numbers divisible by 3 and 5 for a given number
- Python program to print all even numbers in a range
- Program to print numbers in digital form
- Python program to print all odd numbers in a range
- Program to Print Pyramid Pattern using numbers
- Program to print numbers from N to 1 in reverse order
- Python program to print negative numbers in a list
- Python program to print all negative numbers in a range
Improved By : Mithun Kumar