ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมสำหรับพิมพ์รูปแบบสี่เหลี่ยมที่กำหนด
สำหรับสิ่งนี้เราจะได้รับความสูงและลมหายใจของรูปสี่เหลี่ยมผืนผ้า งานของเราคือพิมพ์สี่เหลี่ยมที่มีขนาดที่กำหนดโดยใช้อักขระ “@”
ตัวอย่าง
#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;
} ผลลัพธ์
@@@@ @ @ @ @ @ @ @@@@