Program to print Even Odd Number Pyramid Last Updated : 06 Sep, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 <iostream> 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 <stdio.h> // 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 <?php // php program to print // above pattern function display($n) { // Initialization $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 echo $j; } else{ // displaying the stars echo "*"; } } echo "\n"; } } // Driver Code // Get n $n = 5; // Print the pattern display($n); ?> JavaScript <script> // Javascript program to print Even Odd Number Pyramid // function for creating pattern function Pattern(n) { // Initialization var 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 document.write( j); } else { // displaying the stars document.write("*"); } } document.write("<br>"); } } // driver code // Get n var n = 5; // Print the pattern Pattern(n); // This code is contributed by noob2000. </script> Output* 1* *2* 1*3* *2*4* Complexity Analysis: Time Complexity: O(n2), where n represents the given input.Auxiliary Space: O(1), no extra space is required, so it is a constant. Comment More infoAdvertise with us Next Article Program to print Even Odd Number Pyramid K Kanishk_Verma Follow Improve Article Tags : Misc Strings DSA pattern-printing Practice Tags : Miscpattern-printingStrings Similar Reads Program to print pyramid pattern Write to program to print the pyramid pattern formed of stars Example : Input: n = 6 Output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * We strongly recommend you to minimize your browser and try this yourself first.The idea is to use two for loops for every part of the p 5 min read C++ Program To Print Pyramid Patterns In this article, we will discuss the following top 16 pattern programs in C++ using star ( * ), numbers or other characters. Table of ContentSimple Pyramid Pattern in C++Flipped Simple Pyramid Pattern in C++Inverted Pyramid Pattern in C++Flipped Inverted Pyramid Pattern in C++Triangle Pattern in C++ 15+ min read Program to Print Pyramid Pattern using numbers 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.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 Approach: 1. Use a for loop for printing the number of rows. 2. Use two for loops 5 min read C++ program to print all Even and Odd numbers from 1 to N Given a number N, the task is to print N even numbers and N odd numbers from 1. Examples: Input: N = 5 Output: Even: 2 4 6 8 10 Odd: 1 3 5 7 9 Input: N = 3 Output: Even: 2 4 6 Odd: 1 3 5 Approach: For Even numbers:Even numbers are numbers that are divisible by 2.To print even numbers from 1 to N, tr 4 min read Program to Print a Pattern of Numbers The idea of pattern based programs is to understand the concept of nesting of for loops and how and where to place the alphabets / numbers / stars to make the desired pattern.Write to program to print the pattern of numbers in the following manner using for loop 1 232 34543 4567654567898765In almost 8 min read Like