QQ网名大全

c语言中根据姓名查询成绩

#include "conio.h"
struct student
{
char name [15];
int score;
};
int find (struct student s[]);void main()
{
int i=0;
struct student stu[5];
for(i=0;i<5;i++)
{
printf("输入第%d个学生的姓名:",i+1);
scanf("%s",stu[i].name);
printf("输入第%d个学生的成绩:",i+1);
scanf("%d",&stu[i].score);
}
int nIndex=find(stu);
if(nIndex!=-1)
printf("找到该同学信息,该同学位于第%d个位置(数组下标)",nIndex);
getch();
}int find(struct student s[])
{
char name[15];
int i=0;
int nIndex=-1;
printf("输入要查询学生的姓名:");
scanf("%s",name);
for(i=0;i<5;i++)
{
if(strcmp(s[i].name,name)==0)
{
nIndex=i;
break;
}
}
return nIndex;
}
佚名
2024-05-30 05:30:57
最佳回答
类似问题(10)