程序在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;
}输出结果
@@@@ @ @ @ @ @ @ @@@@