Program to print alphabet "A" using stars

Last Updated : 8 Oct, 2025

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 namespace std;

// Function to display alphabet pattern
void display(int n)
{
    // Outer for loop for number of lines
    for (int i = 0; i < n; i++) {

        // Inner for loop for logic execution
        for (int j = 0; j <= n / 2; j++) {

            // prints two column lines
            if (i==0 || j==0 || j==n/2 || i==n/2)
            {
                if(i==0  && (j==0 || j==n/2))
                cout<<" ";
                else
                cout<<"*";
            }
            else
                cout << " ";
        }

        cout << '\n';
    }
}
// Driver Function
int main()
{
    display(7);
    return 0;
}
Java
// Java program to print alphabet A pattern
import java.io.*;

class GFG {
    // Function to display alphabet pattern
    static void display(int n) {
        
        // Outer for loop for number of lines
        for (int i = 0; i < n; i++) {
            
            // Inner for loop for logic execution
            for (int j = 0; j <= n / 2; j++) {
                
                // prints two column lines
                if (i==0 || j==0 || j==n/2 || i==n/2) {
                    if(i==0  && (j==0 || j==n/2))
                        System.out.print(" ");
                    else
                        System.out.print("*");
                }
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
    }
    // Driver Function
    public static void main(String[] args) {
        display(7);
    }
}
Python
# Function to display alphabet pattern
def display(n):
    # Outer for loop for number of lines
    for i in range(n):
        
        # Inner for loop for logic execution
        for j in range(n // 2 + 1):
            
            # prints two column lines
            if i==0 or j==0 or j==n//2 or i==n//2:
                if i==0 and (j==0 or j==n//2):
                    print(" ", end="")
                else:
                    print("*", end="")
            else:
                print(" ", end="")
        print()

if __name__ == '__main__':
    display(7)
C#
using System;

class Program {
    
    // Function to display alphabet pattern
    static void Display(int n) {
        
        // Outer for loop for number of lines
        for (int i = 0; i < n; i++) {
            
            // Inner for loop for logic execution
            for (int j = 0; j <= n / 2; j++) {
                
                // prints two column lines
                if (i==0 || j==0 || j==n/2 || i==n/2) {
                    if(i==0  && (j==0 || j==n/2))
                        Console.Write(" ");
                    else
                        Console.Write("*");
                }
                else
                    Console.Write(" ");
            }
            Console.WriteLine();
        }
    }
    // Driver Function
    static void Main() {
        Display(7);
    }
}
JavaScript
function display(n) {
    
    // Outer for loop for number of lines
    for (let i = 0; i < n; i++) {
        let line = "";
        
        // Inner for loop for logic execution
        for (let j = 0; j <= Math.floor(n / 2); j++) {
            
            // prints two column lines
            if (i===0 || j===0 || j===Math.floor(n/2) || i===Math.floor(n/2)) {
                if(i===0  && (j===0 || j===Math.floor(n/2)))
                    line += " ";
                else
                    line += "*";
            }
            else
                line += " ";
        }
        console.log(line);
    }
}
// Driver Function
display(7);

Output : 
 

 ** 
* *
* *
****
* *
* *
* *

Time Complexity: O(n*n)

Auxiliary Space: O(1)
 

Comment