文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>矩阵的加法与乘法

矩阵的加法与乘法

时间:2011-04-28  来源:qingcheng奕

//矩阵的加法与乘法
#include<iostream>
using namespace std;
#define row 4        //注意格式,这里没有分号
#define colum 3
int main()
{
    int arr[row][colum]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}}; //注意二维数组的赋初值方式
    int arr2[row][colum]={{4,5,6},{1,2,3},{10,11,12},{7,8,9}};
    int add[row][colum];
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<colum;j++)
        {
            add[i][j]=arr[i][j]+arr2[i][j];
            cout<<add[i][j]<<" ";
        }
        cout<<endl;
    }
    int arr3[colum][row]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
    int arr4[row][colum]={0};
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<row;j++)
        {
            arr4[i][j]=0;
            for(int k=0;k<colum;k++)
            {
                arr4[i][j]+=arr[i][k]*arr3[k][j];
            }
            cout<<arr4[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

相关阅读 更多 +
排行榜 更多 +
无限Fps

无限Fps

飞行射击 下载
幸存者时间僵尸

幸存者时间僵尸

飞行射击 下载
金属兄弟Metal Brother

金属兄弟Metal Brother

冒险解谜 下载