Program to print alphabet “A” using stars

15 Apr, 2021
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++
Java
Python3
C#
PHP
Javascript
// CPP program to print alphabet A pattern#include <iostream>using namespace std; // Function to display alphabet patternvoid 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 Functionint main(){    display(7);    return 0;}
// Java program to print alphabet A patternimport 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);    }}
# Python3 program to print alphabet A pattern # Function to display alphabet patterndef 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 Functiondisplay(7)  # This code is contributed by Anant Agarwal.
// C# program to print alphabet A patternusing 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.*/
<?php// php program to print// alphabet A pattern // Function to display// alphabet patternfunction 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?>
<script>   // JavaScript program to print alphabet A pattern   // Function to display alphabet pattern  function display(n)  {    // Outer for loop for number of lines    for (var i = 0; i < n; i++)    {      // Inner for loop for logic execution      for (var j = 0; j <= Math.floor(n / 2); j++)      {        // prints two column lines        if (          ((j == 0 || j == Math.floor(n / 2)) && i != 0) ||          // print first line of alphabet          (i == 0 && j != 0 && j != Math.floor(n / 2)) ||          // prints middle line          i == Math.floor(n / 2)        ) {          document.write("*");        } else document.write("  ");      }      document.write("<br>");    }  }  // Driver Function  display(7);   </script>
Output :  
 ** 
*  *
*  *
****
*  *
*  *
*  *
 
Mithun Kumar
rdtank
pattern-printing
School Programming
pattern-printing
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.