
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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
@@@@ @ @ @ @ @ @ @@@@
- Related Articles
- C program to print hollow rectangle star pattern
- Swift Program to Print Solid Rectangle Star Pattern
- Swift program to print hollow rectangle star pattern
- Program to print number pattern in C
- Program to print Diamond Pattern in C
- Program to print numeric pattern in C
- Program to print pyramid pattern in C
- Program to print Interesting pattern in C++
- Program to print Kite Pattern in C++
- Program to print a pattern of numbers in C++
- C++ Program to Print X Star Pattern
- C++ Program to Print Square Star Pattern
- C++ Program to Print 8 Star Pattern
- Program to print Inverse Diamond pattern on C++
- C++ Program to Print Right Triangle Star Pattern

Advertisements