/*3 输出图形: A
A B
A B C
A B C D
*/
#include<stdio.h>
int main() {
int a[4][7];
for (int i = 0; i < 4; i++) {
for (int j = 0; j <7; j++) {
a[i][j] = 0;
}
}
int j =3,m= 3;
char ch = 'A';
int i = 0,n=0;
for (; i < 4; ) {
a[i][j] =ch;
j--;
i++;
if (i==3)
{
a[i][j] = ch;
i = n+1;
n = i;
ch += 1;
j = m+1;
m = j;
}
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j <7; j++) {
if (a[i][j] == 0)
printf(" ");
else
printf("%c", a[i][j]);
}
printf("\n");
}
}
第二种方法
#include<stdio.h>
int main() {
char ch = 'A';
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 7; j++) {
if (i + j < 3 || j - i>3 || (i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))//将空格打印出来
{
printf(" ");
}
else {
printf("%c",ch);
ch = ch + 1;
}
}
ch = 'A';
printf("\n");
}
}