**提示信息:"Input student’s ID and score:"
**输入格式: "%ld%d"
**提示信息: "Input the searching ID:"
**输入格式要求:"%ld"
**输出格式要求:"Total students are %dn"
"score = %dn" "Not found!n"
程序的两次运行示例如下:
① Input student’s ID and score:1910122 84
Input student’s ID and score:1910123 83
Input student’s ID and score:1910124 88
Input student’s ID and score:1910125 87
Input student’s ID and score:1910126 61
Input student’s ID and score:-1 -1
Total students are 5
Input the searching ID:1910123
score = 83
② Input student’s ID and score:1910122 84
Input student’s ID and score:1910123 83
Input student’s ID and score:1910124 88
Input student’s ID and score:1910125 87
Input student’s ID and score:1910126 61
Input student’s ID and score:-1 -1
Total students are 5
Input the searching ID:1910128
Not found!
#include
#include
int main()
{
int id;
long ID[40];
int score[40];
int j = 0;
do{
printf("Input student’s ID and score:");
scanf("%ld%d", &ID[j], &score[j]);
j++;
}while(ID[j-1] > 0 || score[j-1] > 0);
printf("Total students are %dn", j-1);
printf("Input the searching ID:");
scanf("%ld", &id);
for(int i = 0; i < j-1; i++)
{
if(ID[i] == id)
{
printf("score = %dn", score[i]);
exit(0);
}
}
printf("Not found!n");
}