70,037
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
void PrintV(int m)
{
if(m<1)
return ;
int i = 0;
int x = 0;
while(i<=m-i)
{
x=0;
while(x<m+1)
{
if(x==i || x==m-i)
{
cout<<'*';
}
else
{
cout<<' ';
}
x++;
}
cout<<'\n';
i++;
}
}
int main()
{
PrintV(0);
PrintV(1);
PrintV(5);
PrintV(10);
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "please input n: ";
cin >> n;
for(int i = 0;i < n; i++ )
{
for( int j = 0; j < 2*n; j++ )
{
if( i == n-1 )
{
if( j == i )
cout << "*";
else
{
cout << " ";
}
}
else if(i == j || i == 2*n - j - 1 )
{
cout << "*";
}
else
{
cout << " ";
}
}
cout << endl;
}
return 0;
}