- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHPPhysics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to print a rectangle pattern in C++
In this tutorial, we will be discussing a program to print a given rectangular pattern.
For this we will be given with the height and the breath of the rectangle. Our task is to print the rectangle with the given dimensions using the “@” character.
Example
#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;
}
Output
@@@@ @ @ @ @ @ @ @@@@
Advertisements