2017西安曲江国际车展:如何用二维数组打印空心菱形?

来源:百度文库 编辑:高校问答 时间:2024/05/02 09:42:15

#include "stdio.h"
main()
{
int i,j;
unsigned char s[11][11];
for (j=0;j<11;j++)
for (i=0;i<11;i++) s[i][j] = '#';
for (j=1;j<=5;j++)
for (i=5-j+1;i<=5+j-1;i++)
s[i][j] = ' ';

for (j=0;j<=5;j++)
for (i=5-j+1;i<=5+j-1;i++) s[i][10-j] = ' ';
for (j=0;j<11;j++){
for (i=0;i<11;i++){
printf("%c",s[i][j]);
}
printf("\n");
}
}
###########
##### #####
#### ####
### ###
## ##
# #
## ##
### ###
#### ####
##### #####
###########