# include <stdio.h>
# define ARR_SIZE 40 // 定义数组的长度
int FindMax( int score[],long num[],int n,long *PMaxNum);
main()
{
int score[ARR_SIZE],maxScore,n,i;
long num[ARR_SIZE],maxNum;
printf("Please Enter Total Numbern");
scanf("%d",&n); /*从键盘输入学生人数n*/
printf("Please Enter the Number and score:n");
for(i=0;i<n;i++) /*分别以长整型和整型格式输入学生的学号和成绩*/
{
scanf("%d,%d",&num[i],&score[i]);
}
maxScore=FindMax(score,num,n,&maxNum); /*计算最高分及其学号*/
printf("maxScore=%d,maxNum=%dn",maxScore,maxNum);
}
/* 函数功能:计算最高分及最高分学生的学号
函数参数:整型数组score,存储学生的成绩
长整型数组num,存储学生的学号
长整型指针变量pMaxNum,存储求出来的最高分学生的学号
函数返回值:最高分
*/
int FindMax( int score[],long num[],int n,long *PMaxNum)
{
int i;
int maxScore;
maxScore=score[0];
//*PMaxNum=num[0]; /*假设score[0]为最高分*/
for(i=1;i<n;i++)
if(score[i]>maxScore)
{
maxScore=score[i]; /*记录最高分*/
*PMaxNum=num[i]; /*记录最高分学生的学号num[i]*/
}
return(maxScore); /*返回最高分maxScore*/
}
转载于:.html
本文发布于:2024-01-31 18:38:57,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170669754030549.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |