C++ Program to Print Right Arrow Number Pattern

Write a C++ program to print right arrow number pattern using for loop.

#include<iostream>
using namespace std;

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

    cout << "Right Arrow Number Pattern\n"; 

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

    for(i = 1; i < rows; i++)
    {
    	for(j = 1; j <= rows; j++)
		{
            if(j < rows - i) {
                cout << " ";
            } 
            else {
                cout << j;
            }
        }
        cout << "\n";
    }	
 	return 0;
}
C++ Program to Print Right Arrow Number Pattern

This C++ example prints the numbers in a right arrow pattern using a while loop.

#include<iostream>
using namespace std;

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

    cout << "Right Arrow Number Pattern\n"; 

    while(i <= rows)
    {
        j = 1;
    	while( j <= rows)
		{
            if(j < i) {
                cout << " ";
            } 
            else {
                cout << j;
            }    
            j++;
        }
        cout << "\n";
        i++;
    }	
    i = 1;
    while( i < rows)
    {
        j = 1;
    	while( j <= rows)
		{
            if(j < rows - i) {
                cout << " ";
            } 
            else {
                cout << j;
            }
            j++;
        }
        cout << "\n";
        i++;
    }	
 	return 0;
}
Enter Right Arrow Number Pattern Row = 9
Right Arrow Number Pattern
123456789
 23456789
  3456789
   456789
    56789
     6789
      789
       89
        9
       89
      789
     6789
    56789
   456789
  3456789
 23456789
123456789

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.