Given a number N which represents the number of rows. The task is to print a half diamond Number-Star pattern as shown in the below examples.
Note: N is always an even number.
Input: N = 4 Output: 2*2 1 1 2*2 Input: N = 6 Output: 3*3*3 2*2 1 1 2*2 3*3*3
On carefully observing the above pattern, it can be broken down into two different triangles:
- An upside down right angled triangle.
- A normal right angled triangle.
For the first triangle pattern:
- Run two loops, first will take care of the number of rows and other will take care of the ‘*’ and numbers being printed.
- Inside the loops check whether the iterations of inner loop has reached to the given number of rows or not.
- If yes, print only number, otherwise print ‘*’ and number both.
The same approach will be followed for the second triangle pattern with a slight change that here the condition will be checked where the inner iteration is equal to 0 or not.
Below is the implementation of above approach:
3*3*3 2*2 1 1 2*2 3*3*3
- Program to print Inverse Diamond pattern
- Program to print numbers with diamond pattern
- Program to print hollow pyramid and diamond pattern
- Program for diamond pattern with different layers
- Program to print the diamond shape
- Program to print the pattern ‘D’
- Program to print the given Z Pattern
- Program to print pattern
- Program to print the given H Pattern
- Program to print the pattern "GFG"
- Program to print the pattern 'G'
- Program to print V and inverted-V pattern
- Program to print number pattern
- Program to print a rectangle 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 email@example.com. 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.