
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
@@@@ @ @ @ @ @ @ @@@@
- Related Questions & Answers
- C program to print hollow rectangle star pattern
- Program to print Interesting pattern in C++
- Program to print Kite Pattern in C++
- 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 a pattern of numbers in C++
- Program to print a matrix in Diagonal Pattern.
- Program to print Inverse Diamond pattern on C++
- Java program to print a given pattern. (stars)
- PHP program to print a pattern of pyramid
- C Program to print hollow pyramid and diamond pattern
- Program to print hollow pyramid and diamond pattern in C++
- Program to print an inverse pyramid character pattern in C++
Advertisements