Write a C++ program to print the hollow rectangle star pattern using for loop.
#include<iostream>
using namespace std;
int main()
{
int i, j, rows, columns;
cout << "Enter Hollow Rectangle Rows = ";
cin >> rows;
cout << "Enter Hollow Rectangle Columns = ";
cin >> columns;
cout << "Hollow Rectangle Star Pattern\n";
for(i = 0; i < rows; i++)
{
for(j = 0; j < columns; j++)
{
if (i == 0 || i == rows - 1 || j == 0 || j == columns - 1)
{
cout << "*";
}
else
{
cout << " ";
}
}
cout << "\n";
}
return 0;
}

This C++ example prints the hollow rectangle pattern of a given character using a while loop.
#include<iostream>
using namespace std;
int main()
{
int i = 0, j, rows, columns;
char ch;
cout << "Enter Hollow Rectangle Rows and Columns = ";
cin >> rows >> columns;
cout << "Enter Symbol for Hollow Rectangle = ";
cin >> ch;
cout << "Hollow Rectangle Star Pattern\n";
while( i < rows)
{
j = 0;
while(j < columns)
{
if (i == 0 || i == rows - 1 || j == 0 || j == columns - 1)
{
cout << ch;
}
else
{
cout << " ";
}
j++;
}
cout << "\n";
i++;
}
return 0;
}
Enter Hollow Rectangle Rows and Columns = 14 25
Enter Symbol for Hollow Rectangle = #
Hollow Rectangle Star Pattern
#########################
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
#########################