编写一个C++程序,使用for循环打印星形三角形的左面通分。
#include 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 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
&
& &
& & &
& & & &
& & & & &
& & & & & &
& & & & & & &
& & & & & & & &
& & & & & & & & &
& & & & & & & & & &
& & & & & & & & & & &
& & & & & & & & & & & &
& & & & & & & & & & & & &
& & & & & & & & & & & &
& & & & & & & & & & &
& & & & & & & & & &
& & & & & & & & &
& & & & & & & &
& & & & & & &
& & & & & &
& & & & &
& & & &
& & &
& &
&