#include <stdio.h>
#include <stdlib.h> //定义宏头文件
#include <time.h> //生成随机函数头文件
#define LEN 10 //宏定义数组长度
#define PH "%02d " //宏定义
int find_max(int arr[],int len) //找数组最大值函数
{
int max = arr[0]; //假设最大值为arr[0]
for(int i=1; i<len; i++) //遍历找最大值
{
if(arr[i] > max)
{
max = arr[i];
}
}
return max;
}
int main(int argc,const char* argv[])
{
srand(time(NULL));
int arr[LEN] = {};
for(int i=0; i<LEN; i++)
{
arr[i] = rand()%100; //生成10个随机数
printf("%d ",arr[i]);
}
printf("\nmax=%d\n",find_max(arr,LEN)); //调用find_max函数找最大值