/*使用递归方法求一个数组的最小值.*/ #include <iostream> #include <time.h> using namespace std; #define MAXSIZE 20 int f(int A[],int n){ if(n==0){ return A[0]; } else{ return ((f(A,n-1)<A[n])?f(A,n-1):A[n]); } } void main(){ int arr[MAXSIZE]; srand((unsigned)time(NULL));//the seed of the random number. for(int i=0;i<MAXSIZE;i++){ arr[i]=rand(); cout<<arr[i]<<" "; }//build an random array. cout<<endl; cout<<"the minimum of the array is:"<<f(arr,MAXSIZE)<<endl; }