Program to print diamond pattern using numbers and stars Last Updated : 31 Oct, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Program to print the following pattern of a half diamond for N. Pattern for N = 4Example: Input: N = 5Output: 1 2*3 4*5*6 7*8*9*10 11*12*13*14*15 11*12*13*14*15 7*8*9*10 4*5*6 2*3 1 This program is divided into four parts. C++ // C++ program to print the half diamond // pattern using numbers and stars #include <iostream> using namespace std; void pattern(int N) { int i, j, count = 1; // This is upper half of pattern for (i = 1; i <= N; i++) { // for loop to display number // upto i for (j = 1; j <= i; j++) { if (j < i) cout << count++ << "*"; else cout << count++; } cout << endl; } count = count - N; // This is lower half of pattern for (i = N; i >= 1; i--) { // for loop to display number // upto i for (j = 1; j <= i; j++) { if (j < i) cout << count++ << "*"; else cout << count++; } count = (count + 1) - 2 * i; cout << endl; } } // Driver code int main() { int N = 4; // Function call pattern(N); return 0; } Java // Java program to print the half diamond // pattern using numbers and stars public class GFG { // Function to print half diamond // pattern using numbers and stars public static void pattern(int N) { int i, j, count = 1; // This is upper half of pattern for (i = 1; i <= N; i++) { // for loop to display number // upto i for (j = 1; j <= i; j++) { if (j < i) System.out.print(count++ + "*"); else System.out.print(count++); } System.out.println(); } count = count - N; // This is lower half of pattern for (i = N; i >= 1; i--) { // for loop to display number // upto i for (j = 1; j <= i; j++) { if (j < i) System.out.print(count++ + "*"); else System.out.print(count++); } count = (count + 1) - 2 * i; System.out.println(); } } // Driver code public static void main(String[] args) { int N = 4; // Function call pattern(N); } } Python3 def pattern(N): count = 1 # This is upper half of pattern for i in range(1, N+1): for j in range(1, i+1): if j < i: print(count, end='*') else: print(count, end='') count += 1 print() count = count - N # This is lower half of pattern for i in range(N, 0, -1): for j in range(1, i+1): if j < i: print(count, end='*') else: print(count, end='') count += 1 count = (count + 1) - 2 * i print() # Driver code if __name__ == '__main__': N = 4 # Function call pattern(N) C# // C# program to print the half diamond // pattern using numbers and stars using System; public class Program { static void pattern(int N) { int i, j, count = 1; // This is upper half of pattern for (i = 1; i <= N; i++) { // for loop to display number // upto i for (j = 1; j <= i; j++) { if (j < i) Console.Write(count++ + "*"); else Console.Write(count++); } Console.WriteLine(); } count = count - N; // This is lower half of pattern for (i = N; i >= 1; i--) { // for loop to display number // upto i for (j = 1; j <= i; j++) { if (j < i) Console.Write(count++ + "*"); else Console.Write(count++); } count = (count + 1) - 2 * i; Console.WriteLine(); } } public static void Main() { int N = 4; // Function call pattern(N); } } JavaScript // JavaScript program to print the half diamond // pattern using numbers and stars // Function to print half diamond // pattern using numbers and stars function pattern(N) { let i, j, count = 1; // This is upper half of pattern for (i = 1; i <= N; i++) { // for loop to display number upto i let row = ""; for (j = 1; j <= i; j++) { if (j < i) { row += count++ + "*"; } else { row += count++; } } console.log(row); } count = count - N; // This is lower half of pattern for (i = N; i >= 1; i--) { // for loop to display number upto i let row = ""; for (j = 1; j <= i; j++) { if (j < i) { row += count++ + "*"; } else { row += count++; } } count = (count + 1) - 2 * i; console.log(row); } } // Driver code let N = 4; // Function call pattern(N); Output1 2*3 4*5*6 7*8*9*10 7*8*9*10 4*5*6 2*3 1 Time Complexity: O(N2) Auxiliary Space: O(1) since we are not using any extra space Comment More infoAdvertise with us Next Article Program to print diamond pattern using numbers and stars N not_mr_abhi Follow Improve Article Tags : DSA school-programming Similar Reads Program to print half Diamond star pattern Given an integer N, the task is to print half-diamond-star pattern. ************************************ Examples: Input: N = 3 Output: * ** *** ** * Input: N = 6 Output: * ** *** **** ***** ****** ***** **** *** ** * Approach: The idea is to break the pattern into two halves that is upper half and 4 min read Program to print number with star pattern We have to print the pattern as given in the below example.Examples : Input : 5 Output : 1 1*2 1*2*3 1*2 1 Input : 9 Output : 1 1*2 1*2*3 1*2*3*4 1*2*3*4*5 1*2*3*4 1*2*3 1*2 1 C++ #include <iostream> using namespace std; // C++ program to print above pattern void display(int n) { // 'sp' used 6 min read Programs to print Triangle and Diamond patterns using recursion This article is aimed at giving a recursive implementation for pattern printing. Pattern 1: Example:Input: 5 Output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *Implementation: C++ // Program to print the given pattern #include <iostream> using namespace std; void print_asterisk 15+ min read Program to print alphabet "A" using stars Given the number of lines n, print the alphabet A pattern using stars.Examples : Input : Number of lines : 5 Output : * * * *** * * * * Input : Number of lines : 10 Output : **** * * * * * * * * ****** * * * * * * * * C++ // CPP program to print alphabet A pattern #include <iostream> using nam 5 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