21 lines
360 B
C
21 lines
360 B
C
|
#include <stdio.h>
|
||
|
|
||
|
int max(int *p, int size)
|
||
|
{
|
||
|
int m = *p; // 默认为第一个元素是最大
|
||
|
for (int i = 1; i < size; i++)
|
||
|
{
|
||
|
if (m < *(p + i))
|
||
|
m = *(p + i);
|
||
|
}
|
||
|
return m;
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
int a[3] = {1, 5, 2};
|
||
|
int m = max(a, 3); // a 表示第一个元素的地址
|
||
|
printf("m max %d\n", m);
|
||
|
|
||
|
return 0;
|
||
|
}
|