题目
、输入一个2*3的二维数组,找出最大值以及它的行下标和列下标,并输出该矩阵
输入输出示例:
Enter a array(2*3):5 8 9 6 -5 -2
max=a[0][2]=9
5 8 9
6 -5 -2
输入输出示例:
Enter a array(2*3):5 8 9 6 -5 -2
max=a[0][2]=9
5 8 9
6 -5 -2
提问时间:2020-11-18
答案
using namespace std;
class SUM
{
private:
int C_array[5][5];
int s;
int a;
int b,m,n;
public:
SUM(){}
SUM(int temp[5][5])
{
int i,j;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
C_array[i][j] = temp[i][j];
s = 0;
a = 1;
b = 0;
m = 0;
n = 0;
}
void process1()
{
int i = 0,j = 4;
for(i=0;i<5;i++)
{
s+=C_array[i][i];
}
for(i=0;i<5;i++)
for(j = 4;j>=0;j--)
{
if(i+j==4&&i!=j)
s+=C_array[i][j];
}
cout<<"对角线上所有元素的和为:"<<s<<endl;
}
void process2()
{
int i = 0,j=4;
for(i=0;i<5;i++)
{
if((i+1)%2==0)
a*=C_array[i][i];
}
for(i=0;i<5;i++)
for(j=4;j>=0;j--)
{
if((i+j==4)&&(i!=j)&&((i+1)%2==0)&&((j+1)%2==0))
a*=C_array[i][j];
}
cout<<"对角线上所有下标为偶数的元素的积为:"<<a<<endl;
}
void process3()
{
int i=0,j=0;
b = C_array[0][0];
m = 0;
n = 0;
for(i=0;i<5;i++)
{
if(b<C_array[i][i])
{
b = C_array[i][i];
m = i;
n = i;
}
}
for(i=0;i<5;i++)
{
for(j=4;j>=0;j--)
{
if(i+j==4&&i!=j)
{
if(b<C_array[i][j])
{
b = C_array[i][j];
m = i;
n = j;
}
}
}
}
cout<<"矩阵中对角线上最大元素是:"<<b<<","<<"在矩阵的位置是第"<<m+1<<"行"<<n+1<<"列."<<endl;
}
};
void main()
{
int t[5][5];
int i,j;
cout<<"请输入一个5*5的矩阵:"<<endl;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
cin>>t[i][j];
SUM sum(t);
sum.process1();
sum.process2();
sum.process3();
fflush(stdin);
getchar();
}
用VS2008写的,测试过了,没有问题.
另外,站长团上有产品团购,便宜有保证
class SUM
{
private:
int C_array[5][5];
int s;
int a;
int b,m,n;
public:
SUM(){}
SUM(int temp[5][5])
{
int i,j;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
C_array[i][j] = temp[i][j];
s = 0;
a = 1;
b = 0;
m = 0;
n = 0;
}
void process1()
{
int i = 0,j = 4;
for(i=0;i<5;i++)
{
s+=C_array[i][i];
}
for(i=0;i<5;i++)
for(j = 4;j>=0;j--)
{
if(i+j==4&&i!=j)
s+=C_array[i][j];
}
cout<<"对角线上所有元素的和为:"<<s<<endl;
}
void process2()
{
int i = 0,j=4;
for(i=0;i<5;i++)
{
if((i+1)%2==0)
a*=C_array[i][i];
}
for(i=0;i<5;i++)
for(j=4;j>=0;j--)
{
if((i+j==4)&&(i!=j)&&((i+1)%2==0)&&((j+1)%2==0))
a*=C_array[i][j];
}
cout<<"对角线上所有下标为偶数的元素的积为:"<<a<<endl;
}
void process3()
{
int i=0,j=0;
b = C_array[0][0];
m = 0;
n = 0;
for(i=0;i<5;i++)
{
if(b<C_array[i][i])
{
b = C_array[i][i];
m = i;
n = i;
}
}
for(i=0;i<5;i++)
{
for(j=4;j>=0;j--)
{
if(i+j==4&&i!=j)
{
if(b<C_array[i][j])
{
b = C_array[i][j];
m = i;
n = j;
}
}
}
}
cout<<"矩阵中对角线上最大元素是:"<<b<<","<<"在矩阵的位置是第"<<m+1<<"行"<<n+1<<"列."<<endl;
}
};
void main()
{
int t[5][5];
int i,j;
cout<<"请输入一个5*5的矩阵:"<<endl;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
cin>>t[i][j];
SUM sum(t);
sum.process1();
sum.process2();
sum.process3();
fflush(stdin);
getchar();
}
用VS2008写的,测试过了,没有问题.
另外,站长团上有产品团购,便宜有保证
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
- 11、面粉是易散的,但是加上适量的水并揉和,就会变成柔韧的面团,为啥?
- 2从A城到经过B城到C城,一共行了360千米,一辆汽车每小时行60千米,回来时每小时多行10千米
- 3can you tell me ( )the train was invented.
- 4爸爸的身高比强强的2倍少42厘米,爸爸比强强高68厘米,强强的身高是多少厘米?
- 5四边形ABCD在平面直角坐标系中各顶点的坐标为A(-2,0),B(0,-6),C(3,-5),D(7,0),求三角形ABC的面积
- 6The boy in blue is Tom.(in blue修饰名词boy)/穿蓝色衣服的孩子是汤姆.
- 7恐龙有哪些恐龙的特点有哪些
- 8东晋南朝时期江南地区的开发产生了怎样深远的影响?
- 9春给人的感觉是( )的.沉睡了一冬的树呀草呀,在春风的轻抚下,苏醒了,焕发出新的活力,把绿意洒遍人间.春给人的感觉是( )的,从冬天的( )到春天的( ),是不是让你有耳目一新的感觉?
- 10作文“祖国在我心中”怎么写
热门考点
- 1设a>0,函数f(x)=ax+b/x2+1,b为常数. (1)证明:函数f(x)的极大值点和极小值点各有一个; (2)若函数f(x)的极大值为1,极小值为-1,试求a的值.
- 2蝴蝶泉阅读答案
- 3设函数y=f(x)在(-∞,+∞)内有定义,对于给定的正数K,定义函数fK(x)=f(x),f(x)≤KK,f(x)>K.取函数f(x)=2-|x|.当K=1/2时,函数fK(x)的单调递增区间为_.
- 4the apple of one‘s eye 和 the apple in one’s eyes ,这两个是有一个是错的吗?
- 5密码箱有五位秘密忘了两位,一次就把它打开的概率是多少?
- 6一般三角形有几条对称轴
- 7定义[a,b,c]为方程ax^2+bx+c=0 的特征数,下面给出特征数为[2m,1-m,-1-m]的方程的一些结论:
- 8做一个披萨的英语作文
- 9六年级上册数学一课四练44页的19题 高悬赏
- 10分解因式4(x+y)²+5-20(x+y-1)