实现函数,找出数组中的最大值。
函数定义
int find_max_number(int numbers[], int n);
参数说明
numbers
,待寻找的数组n
,表示数组长度,且 n>=0
返回值
返回 numbers
中的最大值
示例1
参数
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;
}