c++输入n输出n行n列的图案。图案中间一行为#字符其他的地方为字符。保证输入的n一定是奇数。输入 一个整数n。输出 一个n×n的矩形。输入样例 5输出样例 #####用时内存 1000MS100MB编辑区 提交
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
// 输出上半部分
for (int i = 0; i < n / 2; i++) {
for (int j = 0; j < n; j++) {
cout << "*";
}
cout << endl;
}
// 输出中间一行
for (int j = 0; j < n; j++) {
cout << "#";
}
cout << endl;
// 输出下半部分
for (int i = n / 2 + 1; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}
``
原文地址: http://www.cveoy.top/t/topic/ilFx 著作权归作者所有。请勿转载和采集!