#include
using namespace std;
int main(int argc, char ** argv){
int width;
cin>>width;
if(width % 2 == 0){
width += 1;
}
for(int i = 0; i != width; i ++){
for(int j = 0 ; j != width; j++){
if( j == (width/2 -i) || j == (width/2 + i) || j == (i - width/2) || j == (width/2 *3 -i))
{
cout<<"*";
}
else{
cout<<" ";
}
}
cout<}
getchar();
return 0;
}
width就是宽度,输入整数,如果是偶数,就加1,这样才能输出完整的菱形。
# include
# include
void main()
{
int i,j,a,b,n;
printf("please enter size");
scanf("%d",&n);
for(i=1;i
for(j=1;j<=n+i-1;j++)
if(j==n-i+1 ||j==n+i-1)
printf("*");
else
printf(" ");
printf("\n");
}
for(i=1;i<=2*n-1;i++)
printf("*");
printf("\n");
for(a=1;a
for(b=1;b<=2*n-a-1;b++)
if(b==n-(n-a-1)||b==2*n-a-1)
printf("*");
else
printf(" ");
printf("\n");}
}