Example
Input
Enter rows : 5
Output
***** * * * * * * *****
Required Knowledge
Basic C++ programming, For loop, Nested loop
Program
#includeusing namespace std; /* * Siddharth Goyal * Chandigarh Engineering College, Landran * */ int main() { int i, j, rows; /* Input number of rows from user */ cout<<"Enter rows : "; cin>>rows; for(i=1; i<=rows; i++) { /* Print trailing spaces */ for(j=1; j<=rows-i; j++) { cout<<" "; } /* Print stars and center spaces */ for(j=1; j<=rows; j++) { if(i==1 || i==rows || j==1 || j==rows) cout<<"*"; else cout<<" "; } cout<<"\n"; } return 0; }