编写一个程序包括主函数和fun函数:主函数的功能是将用户输入的m个人的成绩存放在score数组中,调用fun函数,并输出最高分和最高分所在的序号;函数fun的功能是找到最高分及最高分所在的序号,将最高分存放在max中,将序号存放在Num中;
要求采用2个全局变量实现。
fun函数的原型:void fun(int score[],int m)
测试用例:当score数组中的数据为10、20、30、90、60、70、80 时,main函数输出90,4
编写一个程序包括主函数和fun函数:主函数的功能是将用户输入的m个人的成绩存放在score数组中,调用fun函数,并输出最高分和最高分所在的序号;函数fun的功能是找到最高分及最高分所在的序号,将最高分存放在max中,将序号存放在Num中;
要求采用2个全局变量实现。
fun函数的原型:void fun(int score[],int m)
测试用例:当score数组中的数据为10、20、30、90、60、70、80 时,main函数输出90,4
#include<stdio.h>
int max = 0;
int Num = 0;
void fun(int score[],int m)
{
max = score[0];
Num = 0;
for(int i=1;i<m;i++)
{
if( i+1<=m)
{
if(score[i+1]>score[i]){
max = score[i+1];
Num = i+1;
}
}
}
}
int main()
{
int n = 0; //用于存入学生成绩的临时变量
int m = 10; //学生个数
int score[m]={0}; //存储学生成绩的数组
for(int i=0;i<m;i++) //保存数据
{
scanf("%d",&n);
score[i]=n;
}
fun(score,m); //找最大值
printf("%d,%d",max,Num); //输出
return 0;
}
没有测试,应该没有问题