请C++编程高手进来(在线等)!! 【高分悬赏】

1,编写重载函数Max1可分别求取两个整数,三个整数,两个双精度数,三个双精度数的最大值。并将结果输出。2,(1)编写并测试3*3矩阵转置函数,使用数组保存3*3矩阵。(... 1,编写重载函数Max1可分别求取两个整数,三个整数,两个双精度数,三个双精度数的最大值。并将结果输出。
2,(1)编写并测试3*3矩阵转置函数,使用数组保存3*3矩阵。
(2)使用动态内存分配生成动态数组来重新完成上题,使用指针实现函数的功能。
展开
 我来答
wgl_1027
2011-03-10 · TA获得超过303个赞
知道小有建树答主
回答量:136
采纳率:0%
帮助的人:184万
展开全部
第一题:
#include <iostream>
using namespace std;

int max(int a ,int b)
{
return a>b ? a:b;
}
int max(int a,int b,int c)
{
int x= b>c ? b:c ;
return a>x ? a : x;
}

double max(double a,double b)
{
return a>b ? a:b;
}

double max(double a,double b,double c)
{
double x=b>c? b:c;
return a>x ? a:x;
}

void main()
{
cout<<max(2,3)<<endl;
cout<<max(3,3,5)<<endl;
cout<<max(1.0,2.0)<<endl;
cout<<max(3.5,2.8,5.7)<<endl;
}

第二题:
法案一:
#include <iostream>
using namespace std;

void matrix(int haha[3][3])
{
int temp;
int i=0;
int j=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if(i<j)
{
temp=haha[i][j];
haha[i][j]=haha[j][i];
haha[j][i]=temp;
}
}

}

void main()
{
int i;
int j;
int haha[3][3];
for(i=0;i<3;i++)//赋值,并输出
{
for(j=0;j<3;j++)
{
haha[i][j]=i*3+j;
cout<<haha[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
matrix(haha);

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<haha[i][j]<<" ";
}
cout<<endl;
}

}
方案二:
//数组指针
#include <iostream>
using namespace std;

void matrix(int (*haha)[3])
{
int temp;
int i=0;
int j=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if(i<j)
{
temp=haha[i][j];
haha[i][j]=haha[j][i];
haha[j][i]=temp;
}
}
}

void main()
{
int i=0;
int j=0;
int(* haha)[3]=new int[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
haha[i][j]=i*3+j;
cout<<haha[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
matrix(haha);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<haha[i][j]<<" ";
}
cout<<endl;
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式