Write a C++ program to print square of right increment numbers pattern using for loop.
#include<iostream>
using namespace std;
int main()
{
int rows;
cout << "Enter Square of Right Increment Numbers Rows = ";
cin >> rows;
cout << "Square of Increment Numbers from Right Side\n";
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= rows - i; j++)
{
cout << "1 ";
}
for (int k = 1; k <= i; k++)
{
cout << i << " ";
}
cout << "\n";
}
}

This C++ program displays the square pattern of increment numbers from the right side using a while loop.
#include<iostream>
using namespace std;
int main()
{
int rows, i, j, k;
cout << "Enter Square of Right Increment Numbers Rows = ";
cin >> rows;
cout << "Square of Increment Numbers from Right Side\n";
i = 1;
while (i <= rows)
{
j = 1;
while (j <= rows - i)
{
cout << "1 ";
j++;
}
k = 1;
while (k <= i)
{
cout << i << " ";
k++;
}
cout << "\n";
i++;
}
}
Enter Square of Right Increment Numbers Rows = 8
Square of Increment Numbers from Right Side
1 1 1 1 1 1 1 1
1 1 1 1 1 1 2 2
1 1 1 1 1 3 3 3
1 1 1 1 4 4 4 4
1 1 1 5 5 5 5 5
1 1 6 6 6 6 6 6
1 7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
In this C++ example, squareIncNum function iterates and prints the square pattern where its numbers are incremented from the right hand side.
#include<iostream>
using namespace std;
void squareIncNum(int rows)
{
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= rows - i; j++)
{
cout << "1 ";
}
for (int k = 1; k <= i; k++)
{
cout << i << " ";
}
cout << "\n";
}
}
int main()
{
int rows;
cout << "Enter Square of Right Increment Numbers Rows = ";
cin >> rows;
cout << "Square of Increment Numbers from Right Side\n";
squareIncNum(rows);
}
Enter Square of Right Increment Numbers Rows = 9
Square of Increment Numbers from Right Side
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 2 2
1 1 1 1 1 1 3 3 3
1 1 1 1 1 4 4 4 4
1 1 1 1 5 5 5 5 5
1 1 1 6 6 6 6 6 6
1 1 7 7 7 7 7 7 7
1 8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9