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

# 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*/
}

转载于:https://www.cnblogs.com/newsoul/archive/2009/06/04/1496544.html

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值