Example
Input
Enter number of rows: 5
Output
***** * * * * * * *****
Required Knowledge
Basic C++ programming, conditional statements, loops and nested loops
Program to print hollow square pattern
#include <iostream>using namespace std; /* * Siddharth Goyal * Chandigarh Engineering College, Landran * */ int main() { int i, j, N; cout<<"Enter number of rows: "; cin>>N; for(i=1; i<=N; i++){ for(j=1; j<=N; j++){ if(i==1 || i==N || j==1 || j==N){ cout<<("*"); } else{ cout<<" "; } } cout<<"\n"; } return 0; }