C++ Program to Print Square Number Pattern

Write a C++ Program to Print Square Number Pattern with an example. In this C++ example, we used nested for loop to print 1’s in a square pattern.

```#include<iostream>
using namespace std;

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

cout << "\nPlease Enter Any Side of a Square = ";
cin >> side;

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

return 0;
}```

C++ Program to Print Square Pattern of 0’s

```#include<iostream>
using namespace std;

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

cout << "\nPlease Enter Any Side of a Square = ";
cin >> side;

for(i = 0; i < side; i++)
{
for(j = 0; j < side; j++)
{
cout << "0";
}
cout << "\n";
}

return 0;
}```
``````Please Enter Any Side of a Square = 10
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000``````

C++ Program to Print Square Number Pattern using a While Loop

```#include<iostream>
using namespace std;

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

cout << "\nPlease Enter Any Side of a Square = ";
cin >> side;

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

return 0;
}```
``````Please Enter Any Side of a Square = 7
1111111
1111111
1111111
1111111
1111111
1111111
1111111``````

This C++ Square Number Pattern example allows the user to enter any number, then print that number in the square.

```#include<iostream>
using namespace std;

int main()
{
int number, i, j, side;

cout << "\nPlease Enter Any Side of a Square = ";
cin >> side;

cout << "\nPlease Enter Any Integer Value to Print as a Square = ";
cin >> number;

for(i = 0; i < side; i++)
{
for(j = 0; j < side; j++)
{
cout << number;
}
cout << "\n";
}

return 0;
}```
``````Please Enter Any Side of a Square = 8

Please Enter Any Integer Value to Print as a Square = 9
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999``````