C++ Program to Print a Hollow Rectangle




 Code:

#include <iostream>
using namespace std;

int main()
{
    int rows,columns;
    cout<<"Enter the number of rows:\n";
    cin>>rows;
    cout<<"Enter the number of columns:\n";
    cin>>columns;
    
    for(int i=1;i<=rows;i++)
    {
        for(int j=1;j<=columns;j++)
        {
            if(i==1 || i==rows || j==1 || j==columns)
            {
                cout<<"*";
            }
            else{
                cout<<" ";
            }
        }
        cout<<endl;
    }
    return 0;
}


Output:





AJ Blogs

Hello everyone, My name Arth and I like to write about what I learn. Follow My Website - https://sites.google.com/view/aj-blogs/home

Post a Comment

Previous Post Next Post
Best Programming Books

Facebook

AJ Facebook
Checkout Our Facebook Page
AJ Blogs
Checkout Our Instagram Page