码迷,mamicode.com
首页 > 其他好文 > 详细

矩阵运算

时间:2016-07-05 18:39:54      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

 1 #include<iostream>
 2 using namespace std;
 3 #define B  3    
 4 #define N  4
 5 #define M  5
 6 
 7 void Juzhenchengfa(int a[B][N],int b[N][M])
 8 {
 9     int c[B][M]={0};
10     for(int i=0; i<B; i++)
11         {//a二维数组4行3列,a[i][x],i 运行四次
12         for(int j=0; j<M; j++) //b二维数组3行4列,b[x][j],j 运行四次
13         { 
14             for(int x=0; x<N; x++)
15             {
16                 c[i][j]=c[i][j]+a[i][x]*b[x][j]; 
17             }//k运行3次
18     }
19     }
20     cout<<"最后的结果是"<<endl;
21         for(int i=0; i<B; i++)
22         { 
23             for(int j=0; j<M; j++)
24             {
25                 cout<<c[i][j]<<"  "; //输出矩阵的乘积结果
26             }
27             cout<<endl;
28     }
29 
30 
31 
32 }
33 void Juzhenjiafa(int a[N][M],int b[N][M])
34 {
35 
36 
37 }
38 
39 void main()
40 {
41     int choice;
42     
43     int a[B][N]={{1, 0, 0, 1},
44                    {0, 2, 5, 0},
45                    {0, 6, 3, 9}}; 
46     int b[N][M]=
47                   {{8, 0, 0, 1,5},
48                    {4, 2, 4, 7,5},
49                    {5, 4, 8, 5,5},
50                    {2, 7, 6, 3,5}};
51     int c[N][M]=
52                   {{5, 5, 0, 1,8},
53                    {2, 2, 4, 7,6},
54                    {8, 9, 8, 5,7},
55                    {8, 7, 6, 3,5}};
56     while(1)
57     {
58         cout<<"---------------------------------------------------------"<<endl;
59     cout<<"请选择你要进行的运算"<<endl;
60     cout<<"1.矩阵乘法     2.矩阵加法      3.矩阵减法  4.退出"<<endl;
61     cout<<"---------------------------------------------------------"<<endl;
62     cin>>choice;
63     if(choice==1)
64     {
65         Juzhenchengfa(a,b);
66 
67     }else if(choice==2)
68     {
69     }
70     else if(choice==3)
71     {
72     }
73     
74     
75     }
76 
77 
78 }

 

矩阵运算

标签:

原文地址:http://www.cnblogs.com/sanzangtdashi/p/5644610.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!