C++ primer plus第六版课后编程题答案8.5


 

8.5

修改乱码—-2015.01.20

#include <iostream>
using namespace std;
template <typename AnyType>
AnyType max5(AnyType arr[5])
{
//AnyType max=0;
AnyType max = arr[0];//这里应该是arr[0]
for (int i = 0; i<5; i++){
if (arr[i]>max)
max = arr[i];
}
return max;
};
void main()
{
int a[5] = { 10, 20, 50, 6, 33 };
double b[5] = { 5.2, 3.5, 6.7, 8.8, 4 };
cout << “the amax is ” << max5(a) << endl;
cout << “the bmax is ” << max5(b) << endl;
system(“pause”);
}

——————————————————————————————————————————————————————————————————————————————

以下为乱码,请忽略

</pre><pre code_snippet_id="285699" snippet_file_name="blog_20140410_1_8715504" name="code" class="cpp">#include <iostream>
using namespace std;
template <typename AnyType>
AnyType max5(AnyType arr[5])
{
	//AnyType max=0;
<span style="white-space:pre"></span><pre code_snippet_id="285699" snippet_file_name="blog_20140410_1_8715504" name="code" class="cpp"><span style="white-space:pre">	</span>AnyType max=arr[0];//这里应该是arr[0]

for(int i=0;i<5;i++){if(arr[i]>max)max=arr[i];}return max;};void main85(){int a[5]={10,20,50,6,33};double b[5]={5.2,3.5,6.7,8.8,4};cout<<“the amax is “<<max5(a)<<endl;cout<<“the bmax is “<<max5(b)<<endl;system(“pause”);}


 

 


发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注