C语言输出菱形后面都是字母a,求解
代码如下#include<stdio.h>intmain(){chardiamond[][9]={{'','','','','*'},{'','','*','','','...
代码如下
#include<stdio.h>int main(){ char diamond[][9]={{' ',' ',' ',' ','*'},{' ',' ','*',' ',' ',' ','*'},{'*',' ',' ',' ',' ',' ',' ',' ','*'},{' ',' ','*',' ',' ',' ','*'},{' ',' ',' ',' ','*'}}; int i,j; for(i=0;i<5;i++) { for(j=0;j<9;j++) { printf("%c",diamond[i][j]); } printf("\n"); } return 0;} 展开
#include<stdio.h>int main(){ char diamond[][9]={{' ',' ',' ',' ','*'},{' ',' ','*',' ',' ',' ','*'},{'*',' ',' ',' ',' ',' ',' ',' ','*'},{' ',' ','*',' ',' ',' ','*'},{' ',' ',' ',' ','*'}}; int i,j; for(i=0;i<5;i++) { for(j=0;j<9;j++) { printf("%c",diamond[i][j]); } printf("\n"); } return 0;} 展开
2个回答
展开全部
每行,9个元素,你初始化的,不完全。
如下即可:
#include<stdio.h>
int main()
{
char diamond[][10] = {
{" * "},
{" * * "},
{"* *"},
{" * * "},
{" * "}};
int i, j;
for(i = 0; i < 5; i++) {
for(j = 0; j < 9; j++) {
printf("%c", diamond[i][j]);
}
printf("\n");
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询