C++ 打印方块数字图案程序

编写一个 C++ 程序,带有示例的方块数字图案。在此 C++ 示例中,我们使用嵌套 for 循环在方块图案中打印 1。

#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 Number Pattern

C++ 打印 0 的方块图案程序

#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

使用 While 循环打印方块数字图案的 C++ 程序

#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

这个 C++ 方块数字图案示例允许用户输入任何数字,然后将该数字打印在方块中。

#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