自考新教材-p350_3
源程序:
#include <iostream>
using namespace std;
template <class T>
void f(T a[],int n)
{
T t;
for (int i = 0; i < n / 2; i++)
{
t = a[i];
a[i] = a[n-i-1];
a[n - i - 1] = t;
}
};
int main()
{
int a[5] = {1,21,134,40,50};
int i;
double d[6] = {2.3,10.1,19.1,8.4,7.2};
f(a,5);
f(d,6);
for (i = 0; i < 5; i++)
cout << a[i] << " ";
cout << endl;
for (i = 0; i < 6; i++)
cout << d[i] << " ";
cout << endl;
system("pause");
return 1;
}
运行结果: