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

此 C++ 示例 使用 while 循环打印数字的左侧帕斯卡三角。
#include<iostream>
using namespace std;
int main()
{
int i, j, k, rows;
cout << "Enter Left Pascal Number Triangle Row = ";
cin >> rows;
cout << "Left Pascals Number Triangle Pattern\n";
i = 1;
while(i <= rows)
{
j = i;
while(j < rows)
{
cout << " ";
j++;
}
k = 1;
while( k <= i)
{
cout << k << " ";
k++;
}
cout << "\n";
i++;
}
i = rows;
while( i >= 1)
{
j = i;
while( j <= rows)
{
cout << " ";
j++;
}
k = 1;
while(k < i)
{
cout << k << " ";
k++;
}
cout << "\n";
i--;
}
return 0;
}
Enter Left Pascal Number Triangle Row = 9
Left Pascals Number Triangle Pattern
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1