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++

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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 ((j == 0 || j == n / 2) && i != 0 ||
  
                // print first line of alphabet
                i == 0 && j != 0 && j != n / 2 ||
  
                // prints middle line
                i == n / 2)
                cout << "*";
            else
                cout << " ";
        }
  
        cout << '\n';
    }
}
// Driver Function
int main()
{
    display(7);
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to print alphabet A pattern
import java.util.Scanner;
class PatternA {
    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 ((j == 0 || j == n / 2) && i != 0 ||
  
                    // print first line of alphabet
                    i == 0 && j != 0 && j != n / 2 ||
  
                    // prints middle line
                    i == n / 2)
  
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
  
            System.out.println();
        }
    }
  
    // Driver Function
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        PatternA a = new PatternA();
        a.display(7);
    }
}

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to print alphabet A pattern
  
# 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 ((j == 0 or j == n // 2) and i != 0 or
  
                # print first line of alphabet
                i == 0 and j != 0 and j != n // 2 or
  
                # prints middle line
                i == n // 2):
                print("*", end = "")
            else:
                print(" ", end = "")
          
        print()
      
  
# Driver Function
display(7)
  
  
# This code is contributed by Anant Agarwal. 

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to print alphabet A pattern
using System;
class PatternA {
    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 ((j == 0 || j == n / 2) && i != 0 ||
  
                    // print first line of alphabet
                    i == 0 && j != 0 && j != n / 2 ||
  
                    // prints middle line
                    i == n / 2)
  
                Console.Write("*");
                else
                Console.Write(" ");
            }
  
            Console.WriteLine();
        }
    }
  
    // Driver Function
    public static void Main()
    {
        PatternA a = new PatternA();
        a.display(7);
    }
}
/*This code is contributed by vt_m.*/

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// php program to print
// alphabet A pattern
  
// Function to display
// alphabet pattern
function display($n)
{
      
    // Outer for loop for 
    // number of lines
    for ($i = 0; $i < $n; $i++)
    {
  
        // Inner for loop for 
        // logic execution
        for ($j = 0; $j <= floor($n / 2); $j++)
        {
  
            // prints two column lines
            // print first line of alphabet
            // prints middle line            
            if (($j == 0 || $j == floor($n / 2)) && 
                 $i != 0 || $i == 0 && $j != 0 && 
                 $j != floor($n / 2) ||
                  
                $i == floor($n / 2))
                echo "*";
            else
                echo " ";
        }
  
        echo "\n";
    }
}
// Driver Function
$n=7;
display($n);
  
// This code is contributed by mits
?>

chevron_right



Output :

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


My Personal Notes arrow_drop_up

Hello everyone, I am Bishal KUMAR Dubey and most importantly an idea creator I just love Programming languages and love to know new concepts everyday,every minute,every second Here to help Other GEEKS

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.



Improved By : Mithun Kumar