猿问

新手求大神帮忙debug:指针变量作为参数简单应用

//要求录入学号及对应的分数,找到最高分数,输出最高分数及对应的学号

#include <stdio.h>

#define N 80

int main(){

int n;

int score[N];//分数 

int number[N];//学号 

int maxNum,maxScore;

printf("Input:how many students in the class:\n");

scanf("%d",&n);

printf("Input:the student number and the score");

int i;

for(i=0;i<n;i++){

scanf("%d %d",&number[i],&score[i]);

}//输入学号及对应的分数 

findMax(&maxScore,&maxNum,n,number[],score[]);

printf("maxNum=%d,maxScore=%d",*maxNum,*maxNum);

return 0;

}

//定义函数:寻找最大分数 

void findMax(int* maxScore,int* maxNum,int n,int number[],int score[]){

*maxScore=score[0];

*maxNum=number[0];

int i;

for(i=1;i<n;i=++){

if(score[i]>*maxScore){

*maxScore=score[i];

*maxNum=number[i];

}

}

}


藏宝alo
浏览 1508回答 1
1回答
随时随地看视频慕课网APP
我要回答