//要求錄入學號及對應的分數(shù),找到最高分數(shù),輸出最高分數(shù)及對應的學號#include <stdio.h>#define N 80int main(){ int n; int score[N];//分數(shù)? 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]); }//輸入學號及對應的分數(shù)? findMax(&maxScore,&maxNum,n,number[],score[]); printf("maxNum=%d,maxScore=%d",*maxNum,*maxNum); return 0;}//定義函數(shù):尋找最大分數(shù)?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]; } } }
- 1 回答
- 0 關注
- 1548 瀏覽
添加回答
舉報
0/150
提交
取消