用一维数组和指针变量作函数参数,编程打印某班一门课成绩的最高分和学号

# 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 Number\n");
 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=%d\n",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*/
}

posted @ 2009-06-04 22:43  newsoul  阅读(4748)  评论(1编辑  收藏  举报