matrix

i have difficulty in printing matrix. 5x3 and 3x5
the output are very weird. have negative values.

int main(void)
{
int a, b, c, element; //A, B, C = value of each element in the matrix
int i, j, k;
int array1[5][3], array2[3][5], array3[5][5];

cout<<"This program will the Matrix multiplication for 5x3 matrix and 3x5 matrix.\n"
<<endl;

cout<<"Please enter the value of a = ";
cin>>a;

cout<<"Please enter the value of b = ";
cin>>b;

cout<<"Please enter the value of c = ";
cin>>c;

for (i = 0; i<5; i++)
{
for (j = 0; j<5; j++)
{
for (k = 0; k<3; k++)
{
array2[i][k] = b*((i+1)*10 + k +1);
array1[k][j] = a*((k+1)*10 + (j+1));

element= (array2[i][j]*array1[k][j]);

array3[i][j]= element;
}
cout<<array3[i][j]
<<setw(10);


if(j == 4)
cout<<endl;

}
}

system("pause");
return 0;
}
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
int main(void)
{
int a, b, c, element; //A, B, C = value of each element in the matrix
int i, j, k;
int array1[5][3], array2[3][5], array3[5][5];

cout<<"This program will the Matrix multiplication for 5x3 matrix and 3x5 matrix.\n"
<<endl;

cout<<"Please enter the value of a = ";
cin>>a;

cout<<"Please enter the value of b = ";
cin>>b;

cout<<"Please enter the value of c = ";
cin>>c;

for (i = 0; i<5; i++)
{
for (j = 0; j<5; j++)
{
for (k = 0; k<3; k++)
{
array2[i][k] = b*((i+1)*10 + k +1);
array1[k][j] = a*((k+1)*10 + (j+1));

element= (array2[i][j]*array1[k][j]);

array3[i][j]= element;
}
cout<<array3[i][j]
<<setw(10);


if(j == 4)
cout<<endl;

}
}

system("pause");
return 0;
}
Topic archived. No new replies allowed.