65,211
社区成员
发帖
与我相关
我的任务
分享
int F(int *a , int *b)
{
if(a != b)
if(*a < *b)
return F(a ,b - 1);
else
return F(a + 1,b);
else
return *a;
}



#include <cstdlib>
#include <iostream>
#include <time.h>
#define N 10
using namespace std;
template<class T>
T min(T *a, T n)
{
T temp = a[0];
for(int i = 1; i < n; ++i)
{
temp = (temp<a[i]?temp:a[i]);
}
return temp;
}
int main(int argc, char *argv[])
{
int a[N], k = N; //如果 min(T *a, T n)的n直接用宏那个的话, 默认n是INT的。。。
srand(time(0));
for(int i = 0; i < N; ++i)
{
a[i] = rand()%100;
cout<<a[i]<<" ";
}
cout<<"\nmin:"<<min(a, k)<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}

