Skip to main content

Pattern 5 C++ Program

 Q). Write Program for the below pattern?


=> Program:

#include<iostream>
using namespace std;


int main(){
int n;
cout<<"Enter the number : ";
cin>>n;

for(int i=1;i<=n;i++){
    for(int j=1; j<=n; j++){
        if(i==1 || i==n){
           cout<<"* ";
        }else{
            if(j==1 || j==n){
                 cout<<"* ";
            }else{
                 cout<<"  ";
            }
        }
    }
    cout<<endl;
}

}

Comments