C++ Program to Print Right Pascals Number Triangle

Write a C++ program to print right pascals number triangle using for loop.

#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

This C++ example prints the right pascals triangle of numbers using a while loop.

#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"; 

    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 Right Pascals Number Triangle 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