编写一个 C++ 程序,使用 for 循环打印左侧帕斯卡星形三角形。
#include<iostream>
using namespace std;
int main()
{
int i, j, k, rows;
cout << "Enter Left Pascals Star Triangle Row = ";
cin >> rows;
cout << "Left Pascals Star Triangle Pattern\n";
for(i = 1; i <= rows; i++)
{
for(j = i; j < rows; j++)
{
cout << " ";
}
for(k = 1; k <= i; k++)
{
cout << "* ";
}
cout << "\n";
}
for(i = rows; i >= 1; i--)
{
for(j = i; j <= rows; j++)
{
cout << " ";
}
for(k = 1; k < i; k++)
{
cout << "* ";
}
cout << "\n";
}
return 0;
}

此 C++ 示例 使用 while 循环打印给定字符的左侧帕斯卡三角形图案。
#include<iostream>
using namespace std;
int main()
{
int i = 1, j, k, rows;
char ch;
cout << "Enter Left Pascals Star Triangle Row = ";
cin >> rows;
cout << "Symbol to print Left Pascals Star Triangle = ";
cin >> ch;
cout << "Left Pascals Star Triangle Pattern\n";
while(i <= rows)
{
j = i;
while( j < rows)
{
cout << " ";
j++;
}
k = 1;
while( k <= i)
{
cout << ch << " ";
k++;
}
cout << "\n";
i++;
}
i = rows;
while( i >= 1)
{
j = i;
while( j <= rows)
{
cout << " ";
j++;
}
k = 1;
while( k < i)
{
cout << ch << " ";
k++;
}
cout << "\n";
i--;
}
return 0;
}
Enter Left Pascals Star Triangle Row = 13
Symbol to print Left Pascals Star Triangle = &
Left Pascals Star Triangle Pattern
&
& &
& & &
& & & &
& & & & &
& & & & & &
& & & & & & &
& & & & & & & &
& & & & & & & & &
& & & & & & & & & &
& & & & & & & & & & &
& & & & & & & & & & & &
& & & & & & & & & & & & &
& & & & & & & & & & & &
& & & & & & & & & & &
& & & & & & & & & &
& & & & & & & & &
& & & & & & & &
& & & & & & &
& & & & & &
& & & & &
& & & &
& & &
& &
&