C++ 程序打印字母 A 星形图案

使用 for 循环编写一个 C++ 程序,以打印字母 A(大写)的星形图案。

#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

这个 C++ 示例 使用 while 循环打印给定符号的字母 A 图案。

#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 = #

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