代码如图所示:
#include<stdio.h>
#define ARR_SIZE 40
int Search(long a[],int n, long x);
int main(void)
{
float score[ARR_SIZE];
int n,i,pos;
long num[ARR_SIZE],x;
printf("Please enter the total number:");
//输入有n个学生的时候
scanf("%d",&n);
printf("Please enter the number and score:\n");
//输入n个学生的学号和成绩
for(i=0;i<n;i++)
{
scanf("%d %f",&num[i],&score[i]);
}
printf("Please enter the searching number:");
scanf("%ld",&x);
pos=Search(num,n,x);
if(pos!=-1)
{
printf("score=%4.0f\n",score[pos]);
}
else
{
printf("Not found!\n");
}
return 0;
}
int Search(long a[],int n,long x)
{
int i;
for(i=0;i<n;i++)
{
if(a[i]==x)
{
return (i);
}
}
return -1;
}