C++ 中打印一个矩形图案的程序
本教程中,我们将讨论打印给定的矩形图案的程序。
为此,我们将获得矩形的高度和宽度。我们的任务是使用“@”字符打印出给定尺寸的矩形。
示例
#include<iostream>
using namespace std;
void print_rec(int h, int w){
for (int i=0; i<h; i++){
cout << "\n";
for (int j=0; j<w; j++){
if (i == 0 || i == h-1 ||
j== 0 || j == w-1)
cout << "@";
else
cout << " ";
}
}
}
int main(){
int h = 5, w = 4;
print_rec(h, w);
return 0;
}输出
@@@@ @ @ @ @ @ @ @@@@
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C #
MongoDB
MySQL
Javascript
PHP