C语⾔练习题:出数组中的最⼤值实现函数,出数组中的最⼤值。
函数定义
int find_max_number(int numbers[], int n);
参数说明
numbers,待寻的数组
n,表⽰数组长度,且 n>=0
返回值
返回 numbers 中的最⼤值
⽰例1
参数
c语言数组最大值最小值int numbers[6] = {2, 8, 10, 1, 9, 10}
int n = 6
返回
10
#include <stdio.h>
int find_max_number(int numbers[], int n) {
int max=numbers[0];
for(int i=0;i<n;i++)
{
if(numbers[i]>max) max=numbers[i];
}
return max;
}
int main () {
int numbers[] = {2, 8, 10, 1, 9, 10};
int n = 6;
int result = find_max_number(numbers,n);
printf("%d",result);
return 0;
}