#include <iostream> #include <iomanip> #include <ctime> using namespace std; int Max(int arr[], int n); void main(int argc, char* argv[]) { srand(time(NULL));//随机种子 int array[8]; int length=sizeof(array)/sizeof(array[0]); for(int i=0;i<length;i++) { int ran=rand()%100; if(ran<10||ran>99) { --i; continue; } array[i]=ran; } cout<<"Max="<<Max(array,length)<<endl; } int Max(int arr[], int length) { if (length == 0) return arr[length]; int max = Max(arr, length - 1); return max > arr[length-1] ? max : arr[length-1]; }