
请C++编程高手进来(在线等)!! 【高分悬赏】
1,编写重载函数Max1可分别求取两个整数,三个整数,两个双精度数,三个双精度数的最大值。并将结果输出。2,(1)编写并测试3*3矩阵转置函数,使用数组保存3*3矩阵。(...
1,编写重载函数Max1可分别求取两个整数,三个整数,两个双精度数,三个双精度数的最大值。并将结果输出。
2,(1)编写并测试3*3矩阵转置函数,使用数组保存3*3矩阵。
(2)使用动态内存分配生成动态数组来重新完成上题,使用指针实现函数的功能。 展开
2,(1)编写并测试3*3矩阵转置函数,使用数组保存3*3矩阵。
(2)使用动态内存分配生成动态数组来重新完成上题,使用指针实现函数的功能。 展开
展开全部
第一题:
#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;
}
}
#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;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询