慕粉1330176786 的学生作业:
#include
#include
struct student{
char name[20];
int id;
int score;
}st1 = {“jack”,1,100};
//st在这里是全局变量
//st struct student st;
int main()
{
//int a[3]; //a[0],a[1],a[2]
//结构体数组
struct student st[3] = {{“rose”,2,70},
{“lilei”,3,60},
{“hmm”,4,50}};
struct student *st0 = &st[0];
strcpy(st0-> name,"liudehua");
st0-> id = 99;
st0-> score = 120;
int id;
//1.要求在以上代码的基础上修改,输出st1整个人的信息。
//2.输出st中3个的信息
//3.要求从键盘输入一个id,判断用户输入的id,在st中是否存在。
// 若是存在,输出整个id对应的名字。若是不存在,输出"no exist",程序结束
for (int i = 0; i < 3; i++) {
printf("NAME\tID\tSCORE\n");
printf("%s\t%d\t%d\n",st[i].name,st[i].id,st[i].score);
}
printf("输入一个id\n");
scanf("%d",&id);
for (int i = 0; i < 3; i++) {
if(st[i].id == id){
printf("NAME\tID\tSCORE\n");
printf("%s\t%d\t%d\n",st[i].name,st[i].id,st[i].score);
return 0;
}
}
printf("no exist\n");
return 0;
}