輸入三個數字 如a、b、c
並建立a*b矩陣與b*c矩陣,再給定元素亂數值




 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdlib.h>
#include "stdafx.h"
#include "iostream"
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
int a=0,b=0,c=0;
int ** Matrix1,** Matrix2,** Matrix3;
cout<<"請輸入a、b、c建立a*b與b*c矩陣"<<endl;
cin>>a;
cin>>b;
cin>>c;
cin.get();
cout<<"a*b等於"<<endl;
Matrix1= new int*[a];
for(int i=0;i<a;i++){
Matrix1[i]=new int[b];
for(int j=0;j<b;j++){
Matrix1[i][j]=rand() % 10+1;
cout<< Matrix1[i][j]<<" " ;
}
cout<<endl;
}
cout<<"b*c等於"<<endl;
Matrix2= new int*[b];
for(int i=0;i<b;i++){
Matrix2[i]=new int[c];
for(int j=0;j<c;j++){
Matrix2[i][j]=rand() % 10+1;
cout<< Matrix2[i][j]<<" " ;
}
cout<<endl;
}
cout<< "_____"<<endl;
Matrix3= new int*[a];
for(int i=0;i<a;i++){
Matrix3[i]=new int[c];
for(int j=0;j<c;j++){
int sun=0;
for(int i0=0;i0<b;i0++){
sun=sun+(Matrix1[i][i0]*Matrix2[i0][j]);
}
Matrix3[i][j]=sun;
cout<< Matrix3[i][j]<<" " ;
}
cout<<endl;
}
return 0;
}
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()