手机
当前位置:查字典教程网 >编程开发 >C语言 >利用C++实现矩阵的相加/相称/转置/求鞍点
利用C++实现矩阵的相加/相称/转置/求鞍点
摘要:1.矩阵相加两个同型矩阵做加法,就是对应的元素相加。复制代码代码如下:#includeusingnamespacestd;intmain()...

1.矩阵相加

两个同型矩阵做加法,就是对应的元素相加。

复制代码 代码如下:

#include<iostream>

using namespace std;

int main(){

int a[3][3]={{1,2,3},{6,5,4},{4,3,2}};

int b[3][3]={{4,3,2},{6,5,4},{1,2,3}};

int c[3][3]={0,0,0,0,0,0,0,0,0};

int i,j;

cout<<"Array A:"<<endl;

for(i=0;i<3;i++){

for(j=0;j<3;j++){

c[i][j]+=a[i][j];//实现相加操作1

cout<<"t"<<a[i][j];//输出矩阵A

}

cout<<endl;

}

cout<<endl;

cout<<"Array B:"<<endl;

for(i=0;i<3;i++){

for(j=0;j<3;j++){

c[i][j]+=b[i][j];//实现矩阵操作2

cout<<"t"<<b[i][j];//输出矩阵B

}

cout<<endl;

}

cout<<endl;

cout<<"Array C:"<<endl;

for(i=0;i<3;i++){

for(j=0;j<3;j++){

cout<<"t"<<c[i][j];//输出矩阵C

}

cout<<endl;

}

cout<<endl;

return 0;

}

利用C++实现矩阵的相加/相称/转置/求鞍点1

2.实现矩阵的转置

复制代码 代码如下:

#include<iostream>

using namespace std;

int main(){

int a[3][2]={{4,3},{6,5},{1,2}};

int b[2][3]={0,0,0,0,0,0};

int i,j;

cout<<"Array A:"<<endl;

for(i=0;i<3;i++){

for(j=0;j<2;j++){

cout<<"t"<<a[i][j];//输出矩阵A

b[j][i]=a[i][j];//进行转置操作

}

cout<<endl;

}

cout<<endl;

cout<<"Array B:"<<endl;

for(i=0;i<2;i++){

for(j=0;j<3;j++){

cout<<"t"<<b[i][j];

}

cout<<endl;

}

cout<<endl;

return 0;

}

利用C++实现矩阵的相加/相称/转置/求鞍点2 3.实现矩阵的相乘

一个m行n列的矩阵可以和n列k行的矩阵相乘,得到一个m行k列的矩阵

复制代码 代码如下:

#include<iostream>

using namespace std;

int main(){

int a[3][2]={{4,3},{6,5},{1,2}};

int b[2][3]={{1,2,3},{6,5,4}};

int c[3][3]={0,0,0,0,0,0,0,0,0};

int i,j,k,l;

cout<<"Array A:"<<endl;

for(i=0;i<3;i++){

for(j=0;j<2;j++){

cout<<"t"<<a[i][j];//输出矩阵A

}

cout<<endl;

}

cout<<endl;

cout<<"Array B:"<<endl;

for(i=0;i<2;i++){

for(j=0;j<3;j++){

cout<<"t"<<b[i][j];//输出矩阵B

}

cout<<endl;

}

cout<<endl;

cout<<"Array C:"<<endl;

for(i=0;i<3;i++){

for(j=0;j<3;j++){

for(k=0;k<2;k++){

c[i][j]+=a[i][k]*b[k][j];//实现相乘操作

}

cout<<"t"<<c[i][j];//输出矩阵C

}

cout<<endl;

}

cout<<endl;

return 0;

}

利用C++实现矩阵的相加/相称/转置/求鞍点3

4.求矩阵中的鞍点

在矩阵中行中最大,列中最小的元素就是我们要求的鞍点

复制代码 代码如下:

#include<iostream>

using namespace std;

int main(){

int a[3][4]={{3,2,13,1},{8,7,10,5},{12,11,14,9}};

int i,j,k,ad,q=0;

bool tag;

for(i=0;i<3;i++){

for(j=0;j<4;j++){

cout<<"t"<<a[i][j];

}

cout<<endl;

}

cout<<endl;

for(i=0;i<3;i++){

ad=a[i][0];

tag=true;

for(j=1;j<4;j++){

if(ad<a[i][j]){

k=j;

}//先选出行中最大

}

for(j=0;j<3;j++){

if(a[i][k]>a[j][k]){

tag=false;

};//再选出列中最小

}

cout<<endl;

if(tag==true){

cout<<"鞍点是第"<<(i+1)<<"行,第"<<(k+1)<<"列的"<<a[i][k]<<endl;

q++;

}

}

if(q==0){

cout<<"没有一个鞍点~"<<endl;

}

cout<<endl;

return 0;

}

利用C++实现矩阵的相加/相称/转置/求鞍点4

【利用C++实现矩阵的相加/相称/转置/求鞍点】相关文章:

用C++实现一个链式栈的实例代码

C++实现两个日期间差多少天的解决方法

用C++实现队列的程序代码

C++多态的实现及原理详细解析

解析如何用指针实现整型数据的加法

C/C++实现矩阵的转置(示例代码)

C++实现:螺旋矩阵的实例代码

用C++实现单向循环链表的解决方法

用c语言实现HUP信号重启进程的方法

用C# 实现鼠标框选效果的实现代码

精品推荐
分类导航