哈哈,代码挺简单的,就不解释啦,有不懂的在下面留言哈,笔主水平有限,不喜勿喷啦.
#include<stdio.h>
#define max(s,f)(s>f?s:f)
maxnum(int a[], int begin,int c) { //sizeof在子函数中求不出参数传递的数组大小
int lengch = c - begin; //注意sizeof在子函数中与主函数中求数组长度的区别
if (lengch == 1) {
return a[begin];
}
else {
return max(a[begin], maxnum(a, begin + 1, c));
}
}
int main() {
int a[] = { 1,4,3,10,2 };
int c = sizeof(a) / sizeof(a[0]);
maxnum(a, 0, c);
int m = maxnum(a, 0,c);
printf("%d\n", m);
return 0;```