#include <stdio.h>
#include <stdlib.h>
void passOrdown(struct student *);
void output(struct student *);
struct student {
char name[20];
int score;
char *passdown;
};
int main()
{
struct student stu[3];
int i;
for (i=0; i<3; i++) {
printf("请输入第#%d位同学的姓名: ", i+1);
scanf("%s", stu[i].name);
printf("请输入第#%d位同学c语言的分数:", i+1);
scanf("%d", &stu[i].score);
printf("\n");
}
passOrdown(stu);
output(stu);
return 0;
}
void passOrdown(struct student *p)
{
int i;
for (i=0; i<3; i++) {
if (p->score >= 60)
p->passdown = "pass";
else
p->passdown = "down";
}
}
void output(struct student *q)
{
int i;
printf("\n\n%10s %10s %20s\n", "Name", "Score", "Passdown");
for (i=1; i<42; i++)
printf("=");
printf("\n");
for (i=0; i<3; i++) {
printf("%10s %10d %20s\n", q->name, q->score, q->passdown);
q++;
}
}
改动部分及原因见注释,以下代码可以直接运行