Display Hollow rectangle and square star pattern in C++
Display Hollow rectangle and square star pattern in C++
In this article, we will discuss the concept of the Program to Display Hollow rectangle or square star pattern in C++ programming language
Display Hollow pattern
In this post, we are going to learn how to write Hollow rectangle or square star pattern using for loop,while loop and Do-while loop with example programs
Program 1
Print Hollow rectangle or square star pattern
Using for loop
This program allows the user to enter the number of rows and columns and then it will display Hollow rectangle or square pattern using for loop in C++ language
#include
#include
using namespace std;
int main()
{
int rows,columns,i,j;
cout>rows;//Takes input from user for rows
cout>columns;//Takes input from user for columns
for (i=1; i
When the above code is executed, it produces the following results
OutputHollow rectangle and square star pattern in C++
Program 2
Using while loop
This program allows the user to enter the number of rows and columns and then it will display Hollow rectangle and square pattern using while loop in C++ language
#include
#include
using namespace std;
int main()
{
int rows,columns,i,j;
cout>rows;
cout>columns;
i=1;
while(i
When the above code is executed, it produces the following results
OutputHollow rectangle and square star pattern in C++
Program 3
Using the do-while loop
This program allows the user to enter the number of rows and columns and then it will display Hollow rectangle and square pattern using the do-while loop in C++ language
#include
#include
using namespace std;
int main()
{
int rows,columns,i,j;
cout>rows;
cout>columns;
i=1;
do{
j=1;
do{
if(i==1||i==rows||j==1||j==columns){
cout
When the above code is executed, it produces the following results
OutputHollow rectangle and square star pattern in C++