題目描述
打印空心正方形
輸入描述
輸入一個整數n,1<=n<=100
輸出描述
輸出一個有字符'*'構成的空心正方形(只有邊界上有'*')
樣例輸入
5
樣例輸出
***** * * * * * * *****
1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int n; 6 cin>>n; 7 for(int i=0;i<n;i++) 8 { 9 if(i==0||i==n-1){ 10 for(int j=0;j<n;j++) 11 { 12 cout<<"*"; 13 } 14 cout<<endl; 15 }else{ 16 cout<<"*"; 17 for(int j=0;j<n-2;j++) 18 { 19 cout<<" "; 20 } 21 cout<<"*"; 22 cout<<endl; 23 } 24 25 } 26 }