不用指针变量作为函数参数,使用数组,同时返回最高分数和对应的学号
#include<stdio.h>
#define N 40
int maxScoreAndNum(float score[],int len);
//不用指针变量作为函数参数,使用数组,同时返回最高分数和对应的学号
int main(){
float score[N];
long num[N];
int n;
printf("please enter total number:");
scanf("%d",&n);
printf("please enter the number and score:");
for(int i=0;i<n;i++){
scanf("%ld%f",&num[i],&score[i]);
}
int max = maxScoreAndNum(score,n);
printf("最高分数的学号为:%ld\n最高分数为:%.1f ",num[max],score[max]);
}
int maxScoreAndNum(float score[],int n){
float max = score[0];
int maxI = 0;
//printf("%d\n",len);
for(int i=0;i<n;i++){
if(score[i]>max){
max = score[i];
maxI = i;
}
}
return maxI;
}