运行结果:
Enter the number between 1 and 20: 5
*****
* *
* *
* *
*****
main.cpp
#include <iostream>
using namespace std;
int main() {
unsigned int row;
cout << "Enter the number between 1 and 20: ";
cin >> row;
for (int i = 0; i < row; i++) {
for (int j = 0 ; j < row; j++) {
if (0 < i && i < row - 1 && 0 < j && j < row - 1)
cout << ' ';
else
cout << '*';
}
cout << '\n';
}
}
这篇博客介绍了如何使用C++编程语言实现一个功能,即输入数字n后,程序将输出一个n行n列的矩形。通过示例代码和运行结果,读者可以学习到C++中控制台输出的基本技巧。
3597

被折叠的 条评论
为什么被折叠?



