C++ 程序打印右向帕斯卡数字三角形

编写一个 C++ 程序,使用 for 循环打印右向帕斯卡数字三角形。

#include<iostream>
using namespace std;

int main()
{
	int i, j, rows;
     
    cout << "Enter Right Pascals Number Triangle Row = ";
    cin >> rows;

    cout << "Right Pascals Triangle Number Pattern\n"; 

    for(i = 1; i <= rows; i++)
    {
    	for(j = 1; j <= i; j++)
		{
            cout << j << " ";  
        }
        cout << "\n";
    }	

    for(i = rows - 1; i >= 1; i--)
    {
    	for(j = 1; j <= i; j++)
		{
            cout << j << " "; 
        }
        cout << "\n";
    }	
 	return 0;
}
CPP Program to Print Right Pascals Number Triangle

示例 程序使用 while 循环打印数字的右向帕斯卡三角形。

#include<iostream>
using namespace std;

int main()
{
int i, j, rows;

cout << "Enter Row = ";
cin >> rows;

cout << "Right Pascals Triangle Number Pattern\n";

i = 1;
while( i <= rows)
{
j = 1;
while(j <= i)
{
cout << j << " ";
j++;
}
cout << "\n";
i++;
}

i = rows - 1;
while( i >= 1)
{
j = 1;
while( j <= i)
{
cout << j << " ";
j++;
}
cout << "\n";
i--;
}
return 0;
}
Enter Row = 9
Right Pascals Triangle Number 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