这算法让我膜拜:
if(abs(i - n)+ abs(j - n)== n -1)
交个作业:
#include
#include
usingnamespace std;
int main()
{ cout <<"请输入半菱形高度n"<< endl;
int n=10,i=1;
cin >> n;
cout<<setw(n)<<"*"<<endl;
for(;i<n;++i)
cout <<setw(n-i)<<"*"<<setw(2*i)<<"*"<< endl;
i=i-2;
while(i>0)
{
cout <<setw(n-i)<<"*"<<setw(2*i)<<"*"<< endl;
i--;
}
cout<<setw(n)<<"*"<<"\t\t"<<endl;
return0;
}