#include <iostream>
using namespace std;
int max(int x,int y)
{
return x>y?x:y; //运用三目运算符
}
int arraymax(int a[],int n)
{
int localmax =(n == 2?a[0]:arraymax(a,n-1));
int totalmax=max(localmax,a[n-1]);
cout << "max(" << localmax << "," << a[n-1] << ")=" << totalmax <<" ";
return totalmax;
}
int main()
{
int a[100];
int n;
int i=0;
cin>>n;
while(n--)
{
cin>>a[i];
i++;
}
n=i;
int totalmax=arraymax(a,n);
cout<<totalmax;
return 0;
}
递归求解最大值
于 2024-04-19 18:21:05 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)