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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
using namespace std;
//const int SIZE = 100;
//typedef double Matrix[SIZE][SIZE];
void multiply(double a[2][5], double b[5][2], double c[5][5], int n)
{
int i, j, k;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
{
c[i][j] = 0;
for (k = 0; k < n; k++)
c[i][j] += a[i][k] * b[k][j];
}
}
int main()
{
double count1;
double matrix1[2][5]={{1,2,3,4,5},
{4,5,6,7,8}};
double matrix2[5][2]={ {10,11},
{13,14},
{16,17},
{19,20},
{23,25}};
double matrix3[5][5] ={{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0}};
multiply(matrix1,matrix2,matrix3,10);
cout <<matrix3[0][0]<<endl;
cout <<matrix3[0][1]<<endl;
cout <<matrix3[1][0]<<endl;
cout <<matrix3[1][1]<<endl;
}
~
~
~
~
~
~
~
~
"matrix.cpp" 49L, 1012C written
ws014@cs:~$ c++ matrix.cpp
ws014@cs:~$ a.out
275
-9.63777e+304
518
-1.92755e+305
Segmentation fault (core dumped)
|