Program to print pattern Last Updated : 13 Mar, 2023 Comments Improve Suggest changes Like Article Like Report Given the value of n, print the following pattern.Examples : Input : n = 4 Output : A1 AB12 ABC123 ABCD1234 Input : n = 7 Output : A1 AB12 ABC123 ABCD1234 ABCDE12345 ABCDEF123456 ABCDEFG1234567 Below is the implementation to print the above pattern : C++ // C++ program to print given pattern #include <bits/stdc++.h> using namespace std; // Function to print pattern for // given value of n void pattern(int n) { // Outer "for" loop for number of rows for (int i = 1; i <= n; i++) { int k = 'A'; int m = 1; // Inner "for" loop for number of columns for (int j = 1; j <= (2 * n); j++) { // Logical execution i.e, condition if (j >= n + 1 - i && (j <= n + i)) { if (j <= n) { // Print the alphabets cout << char(k); k++; } else { // Print the numbers cout << m; m++; } } else cout << " "; } // Print the next line cout << endl; } } // Driver Code int main() { int n = 7; // Function calling pattern(n); return 0; } Java // java program to print given pattern import java.util.*; class GFG { // Function to print pattern for // given value of n static void pattern(int n) { // Outer "for" loop for number of rows for (int i = 1; i <= n; i++) { int k = 'A'; int m = 1; // Inner "for" loop for number of // columns for (int j = 1; j <= (2 * n); j++) { // Logical execution i.e, condition if (j >= n + 1 - i && (j <= n + i)) { if (j <= n) { // Print the alphabets System.out.print((char)k); k++; } else { // Print the numbers System.out.print(m); m++; } } else System.out.print(" "); } // Print the next line System.out.println(); } } // Driver Code public static void main(String[] args) { int n = 7; // Function calling pattern(n); } } // This code is contributed by Anuj_67 Python # Python program to # print given pattern # Function to print # pattern for # given value of n def pattern(n): # Outer "for" loop # for number of rows i = 1 while i <= n: k = 65; m = 1; # Inner "for" loop for # number of columns j = 1 while j <= (2 * n): # Logical execution # i.e, condition if (j >= n + 1 - i) and (j <= n + i): if (j <= n): # Print the alphabets print(chr(k)), k += 1 else: # Print the numbers print(m), m += 1 else: print(" "), j += 1 i += 1 # Print the next # line print("\n") # Driver Code def main(): n = 7 # Function calling pattern(n) if __name__=="__main__": main() # This code is contributed # prabhat kumar singh C# // C# program to print given pattern using System; class GFG { // Function to print pattern for // given value of n static void pattern(int n) { // Outer "for" loop for number of rows for (int i = 1; i <= n; i++) { int k = 'A'; int m = 1; // Inner "for" loop for number of // columns for (int j = 1; j <= (2 * n); j++) { // Logical execution i.e, condition if (j >= n + 1 - i && (j <= n + i)) { if (j <= n) { // Print the alphabets Console.Write((char)k); k++; } else { // Print the numbers Console.Write(m); m++; } } else Console.Write(" "); } // Print the next line Console.WriteLine(); } } // Driver Code public static void Main() { int n = 7; // Function calling pattern(n); } } // This code is contributed by Anuj_67 PHP <?php // PHP program to print given pattern // Function to print pattern for // given value of n function pattern($n) { // Outer "for" loop for // number of rows for($i = 1; $i <= $n; $i++) { $k = 'A'; $m = 1; // Inner "for" loop for // number of columns for($j = 1; $j <= (2 * $n); $j++) { // Logical execution i.e, condition if ($j >= $n + 1 - $i && ($j <= $n + $i)) { if ($j <= $n) { // Print the alphabets echo $k; $k++; } else { // Print the numbers echo $m; $m++; } } else echo " "; } // Print the next line echo "\n"; } } // Driver Code $n = 7; // Function calling pattern($n); // This code is contributed by Anuj_67 ?> JavaScript <script> // JavaScript implementation for the above approach // Function to print pattern for // given value of n function pattern(n) { // Outer "for" loop for number of rows for (var i = 1; i <= n; i++) { var k = 65; var m = 1; // Inner "for" loop for number of columns for (var j = 1; j <= (2 * n); j++) { // Logical execution i.e, condition if (j >= n + 1 - i && (j <= n + i)) { if (j <= n) { // Print the alphabets document.write(String.fromCharCode(k)); k++; } else { // Print the numbers document.write(m); m++; } } else document.write(' '+' '); } // Print the next line document.write("<br>"); } } // Driver Code var n = 7; // Function Call pattern(n); // This code is contributed by Shubham Singh </script> Output: A1 AB12 ABC123 ABCD1234 ABCDE12345 ABCDEF123456 ABCDEFG1234567 Time complexity: O(n2) for given input n Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Program to print pattern ukasp Follow Improve Article Tags : School Programming DSA pattern-printing Practice Tags : pattern-printing Similar Reads Program to print Crown Pattern Given the value of length, print the crown pattern using '*' and '#'. Note : In order to print a perfect crown, take the value of length as an odd number greater than 15. Examples : Input: length = 19 Output: * * * # # # ## ### ## ### ##### ### #### ####### #### ################### ################# 7 min read Program to print number pattern We have to print a pattern where in middle column contains only 1, right side columns contain constant digit which is greater than 1 and left side columns contains constant digit which is greater than 1. Every row should look like a Palindrome. Examples : Input : 3 Output : 1 2 1 2 1 Input : 5 Outpu 7 min read Program to print the pattern "GFG" In this article, given the value of n(length of the alphabet) and k(width of the alphabet) we will learn how to print the pattern "GFG" using stars and white-spaces. Examples: INPUT: n=7, k=5 OUTPUT: ***** ***** ***** * * * * * * * ** ***** * *** * * * * * * * * * * ***** * ***** INPUT: n=11, k=7 OU 8 min read 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 Program to print Swastika Pattern Given the number of rows and columns, print the corresponding swastika pattern using loops. Note: The number of rows and columns should be the same and an odd number. This will generate a perfect swastika pattern. Examples : Input : row = 7, column = 7 Output: * * * * * * * * * * * * * * * * * * * * 9 min read Program to print the arrow pattern Given the value of n, print the arrow pattern.Examples : Input : n = 5 Output : * ** *** **** ***** **** *** ** * Input : n = 7 Output : * ** *** **** ***** ****** ******* ****** ***** **** *** ** * Below is the program to print the arrow pattern: C++ // C++ program to print the // arrow pattern #in 10 min read Program to print Sine-Wave Pattern Given two integers waveHeight and waveLength. The task is to print a sine wave pattern using the character 0. The sine wave rises and falls vertically across the given height and repeats horizontally for the given length. Examples:Input: waveHeight = 5, waveLength = 10Output: 0 0 0 0 0 0 0 0 0 0 0 0 15+ 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 the Zigzag pattern 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 : N = 3 Output : 1 3*2 4*5*6 Input : N = 5 Output : 1 3*2 4*5*6 10*9*8*7 11*12*13*14*15 Approach: Use a for loop for printing the number of rows.Use two va 6 min read Program to print the Ladder Pattern Given an integer N, the task is to print the ladder with N steps using '*'. The ladder will be with the gap of 3 spaces between two side rails. Input: N = 3 Output: * * * * ***** * * * * ***** * * * * ***** * * * * Input: N = 4 Output: * * * * ***** * * * * ***** * * * * ***** * * * * ***** * * * * 4 min read Like