应用指针函数求最大分和最小分的学生学号。弃用数组,善于创新。。喜欢的话大家给点意见。。
#include <stdio.h>#define ARR_SIZE 40
void FindMax(float score[],long num[],int n,float *pMaxScore,long *pMaxNum);
main()
{
float score[ARR_SIZE],maxScore;
long num[ARR_SIZE],maxNum;
int n,i;
printf("Please enter total number:");
scanf("%d",&n);
printf("Please enter the number and score:\n");
for (i=0;i<n;i++)
{
scanf("%ld%f",&num[i],&score[i]);
}
FindMax(score,num,n,&maxScore,&maxNum);
printf("maxScore=%.0f,maxNum=%ld\n",maxScore,maxNum);
}
void FindMax(float score[],long num[],int n,float *pMaxScore,long *pMaxNum)
{
int i;
*pMaxScore=score[0];
*pMaxNum=num[0];
for (i=1;i<n;i++)
{
if (score[i]>*pMaxScore)
{
*pMaxScore=score[i];
*pMaxNum=num[i];
}
}
}