B类
1.(原创)请编写一个程序,打印以下图形:
2.(原创)下列程序运行结果为:
#include <stdio.h>
struct haha {
int num;
int digit;
int space;
};
int main() {
struct haha gh[8] = {{6, 0, 0}, {7, 0, 0},
{0, 0, 1}, {21, 0, 0}, {5, 1, 0}, {8, 1, 0},
{7, 1, 0}, {-1, 0, 0}};
struct haha *p = gh;
while (p -> num > -1) {
if (p -> digit) {
putchar('0' + p -> num);
} else if (p -> space) {
putchar(' ');
} else {
putchar('a' + p -> num);
}
p++;
}
putchar('\n');
return 0;
}
B+类
3.(原创)请编写一个程序,用链表的形式存储用户录入的学生信息并打印,如图所示
-----------------------------以下为答案---------------------------------
1.
#include <stdio.h>
int main() {
int i, j;
for (i = 0; i < 27; i++) {
for (j = 0; j < i; j++) {
putchar('Z' - i + j + 1);
}
for (j = 0; j < 26 - i; j++) {
putchar('A' + j);
}
putchar('\n');
}
return 0;
}
2. gh v587
3.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
char name[20];
float score;
struct Student *next;
};
typedef struct Student stu;
int main() {
int i = 0;
stu *head = NULL, *now, *prev;
while (1) {
i++;
printf("请输入第%d位同学的姓名:", i);
now = (stu *)malloc(sizeof(stu));
gets(now -> name);
if (strcmp(now -> name, "end") == 0) {
prev -> next = NULL;
break;
}
printf("请输入第%d位同学的成绩:", i);
scanf("%f", &now -> score);
getchar();
if (head == NULL) {
head = now;
} else {
prev -> next = now;
}
prev = now;
}
printf("------------------------\n");
printf("用户录入的信息如下:\n");
now = head;
while (now) {
printf("姓名:%s\t", now -> name);
printf("成绩:%.1f\n", now -> score);
prev = now;
now = now -> next;
free(prev);
}
return 0;
}