C++ Program to Print Alphabet A Star Pattern

Write a C++ program to print stars in alphabet A (uppercase) pattern using for loop.

#include<iostream>
using namespace std;

int main()
{
	int i, j, k, rows;
     
    cout << "Enter Alphabet A Star Pattern Row = ";
    cin >> rows;

    cout << "Alphabet A Star Pattern\n"; 

    for(i = 0; i < rows; i++)
    {
    	for(j = 0; j <= rows/2; j++)
		{
            if((i == 0 && j != 0 && j != rows/2) || i == rows / 2 || 
            (j == 0 || j == rows /2 ) && i != 0)
            {
                cout << "*";
            }
            else
            {
                cout << " ";
            }
        }
        cout << "\n";
    }	
 	return 0;
}
C++ Program to Print Alphabet A Star Pattern

This C++ example prints the Alphabet A pattern of a given symbol using a while loop.

#include<iostream>
using namespace std;

int main()
{
	int i = 0, j, rows;
    char ch;
     
    cout << "Enter Row = ";
    cin >> rows;

    cout << "Enter Symbol for Alphabet A Pattern = ";
    cin >> ch;


    while(i < rows)
    {
        j = 0;
    	while( j <= rows/2)
		{
            if((i == 0 && j != 0 && j != rows/2) || i == rows / 2 || 
            (j == 0 || j == rows /2 ) && i != 0)
            {
                cout << ch;
            }
            else
            {
                cout << " ";
            }
            j++;
        }
        cout << "\n";
        i++;
    }	
 	return 0;
}
Enter Row = 10
Enter Symbol for Alphabet A Pattern = #

 #### 
#    #
#    #
#    #
#    #
######
#    #
#    #
#    #
#    #

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.