# Program to print Even Odd Number Pyramid

Given the total number of rows as n, the task is to print the given pattern.

*
1*
*2*
1*3*
*2*4*
1*3*5*
*2*4*6*
1*3*5*7*
*2*4*6*8*
1*3*5*7*9*
.
.

Examples:

```Input: n = 5
Output:
*
1*
*2*
1*3*
*2*4*

Input: n = 10
Output:
*
1*
*2*
1*3*
*2*4*
1*3*5*
*2*4*6*
1*3*5*7*
*2*4*6*8*
1*3*5*7*9*
```

Below is the solution to the above problem:

## C++

 `// CPP program to print Even Odd Number Pyramid ` ` `  `#include ` `using` `namespace` `std; ` ` `  `// function for creating pattern ` `void` `Pattern(``int` `n) ` `{ ` `    ``// Initialization ` `    ``int` `i, j, k; ` `    ``for` `(i = 1; i <= n; i++) { ` ` `  `        ``for` `(j = 1, k = i; j <= i; j++, k--) { ` ` `  `            ``if` `(k % 2 == 0) { ` ` `  `                ``// displaying the numbers ` `                ``cout << j; ` `            ``} ` `            ``else` `{ ` ` `  `                ``// displaying the stars ` `                ``cout << ``"*"``; ` `            ``} ` `        ``} ` `        ``cout << ``"\n"``; ` `    ``} ` `} ` ` `  `// driver code ` `int` `main() ` `{ ` ` `  `    ``// Get n ` `    ``int` `n = 5; ` ` `  `    ``// Print the pattern ` `    ``Pattern(n); ` ` `  `    ``return` `0; ` `} `

## C

 `// C program to print Even Odd Number Pyramid ` ` `  `#include ` ` `  `// function for creating pattern ` `void` `Pattern(``int` `n) ` `{ ` `    ``// Initialization ` `    ``int` `i, j, k; ` `    ``for` `(i = 1; i <= n; i++) { ` `        ``for` `(j = 1, k = i; j <= i; j++, k--) { ` `            ``if` `(k % 2 == 0) { ` ` `  `                ``// displaying the numbers ` `                ``printf``(``"%d"``, j); ` `            ``} ` `            ``else` `{ ` ` `  `                ``// displaying the stars ` `                ``printf``(``"*"``); ` `            ``} ` `        ``} ` `        ``printf``(``"\n"``); ` `    ``} ` `} ` ` `  `// driver code ` `int` `main() ` `{ ` ` `  `    ``// Get n ` `    ``int` `n = 5; ` ` `  `    ``// Print the pattern ` `    ``Pattern(n); ` ` `  `    ``return` `0; ` `} `

## Java

 `// Java program to print above pattern ` ` `  `import` `java.util.Scanner; ` ` `  `class` `Pattern { ` `    ``static` `void` `display(``int` `n) ` `    ``{ ` ` `  `        ``int` `i, j, k; ` `        ``for` `(i = ``1``; i <= n; i++) { ` ` `  `            ``for` `(j = ``1``, k = i; j <= i; j++, k--) { ` ` `  `                ``if` `(k % ``2` `== ``0``) { ` `                    ``// displaying the numbers ` `                    ``System.out.print(j); ` `                ``} ` `                ``else` `{ ` `                    ``// displaying the stars ` `                    ``System.out.print(``"*"``); ` `                ``} ` `            ``} ` `            ``System.out.print(``"\n"``); ` `        ``} ` `    ``} ` `    ``// Driver Code ` `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``// Get n ` `        ``int` `n = ``5``; ` ` `  `        ``// Print the pattern ` `        ``display(n); ` `    ``} ` `} `

## Python3

 `# Python3 program to print above pattern  ` `def` `display(n): ` `    ``for` `i ``in` `range``(``1``, n ``+` `1``): ` `        ``k ``=` `i ` `        ``for` `j ``in` `range``(``1``, i ``+` `1``): ` `            ``if` `k ``%` `2` `=``=` `0``: ` `                 `  `                ``# Displaying the numbers  ` `                ``print``(j, end ``=` `'') ` `            ``else``: ` `                 `  `                ``# Displaying the stars  ` `                ``print``(``'*'``, end ``=` `'') ` `            ``k ``-``=` `1` `        ``print``() ` ` `  `# Driver Code  ` ` `  `# Get n  ` `n ``=` `5` ` `  `# Print the pattern  ` `display(n) ` ` `  `# This code is contributed by SamyuktaSHegde  `

## C#

 `// C# program to print above pattern ` `using` `System; ` ` `  `class` `GFG ` `{ ` `static` `void` `display(``int` `n) ` `{ ` ` `  `    ``int` `i, j, k; ` `    ``for` `(i = 1; i <= n; i++)  ` `    ``{ ` ` `  `        ``for` `(j = 1, k = i; j <= i; j++, k--)  ` `        ``{ ` ` `  `            ``if` `(k % 2 == 0)  ` `            ``{ ` `                ``// displaying the numbers ` `                ``Console.Write(j); ` `            ``} ` `            ``else`  `            ``{ ` `                ``// displaying the stars ` `                ``Console.Write(``"*"``); ` `            ``} ` `        ``} ` `        ``Console.Write(``"\n"``); ` `    ``} ` `} ` ` `  `// Driver Code ` `public` `static` `void` `Main() ` `{ ` ` `  `    ``// Get n ` `    ``int` `n = 5; ` ` `  `    ``// Print the pattern ` `    ``display(n); ` `} ` `} ` ` `  `// This code is contributed by anuj_67 `

## PHP

 `  `

Output:

```*
1*
*2*
1*3*
*2*4*
```

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.