用两种数组方法输出菱形
- 用字符串输入
- 用多个字符输入
一、用字符串输入
程序………………
#include<stdio.h>
int main()
{
char diamond[5][5]={{" * "},{" * * "},{"* *"},{" * * "},{" * "}};
int i,j; //{{" *"} ,{" * *"} ,{"* *"},{" * *"} ,{" *"}}; 这样也对
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
printf("%c",diamond[i][j]);
printf("\n");
}
return 0;
}
运行结果………………
二、用多个字符输入
程序………………
#include<stdio.h>
int main()
{
char diamond[5][5]={{' ',' ','*',' ',' '},{' ','*',' ','*',' '},{'*',' ',' ',' ','*'},{' ','*',' ','*',' '},{' ',' ','*',' ',' '}};
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
printf("%c",diamond[i][j]);
printf("\n");
}
return 0;
}
运行结果………………