1. ## multiplying matrices

i've written a program that will multiply two matrices, and as of right now it outputs the answers all in column..I was attempting to be able to output the answers in another matrix, matrix C, but I have no idea how to even get around to doing that. I did all I knew, which was to declare the matrix..other than that im stuck
...any suggestions to help me out?

my code thus far:

Code:
```

include <iostream>			//library for basic
#include <math.h>

using namespace std;

//declare functions
void matrixA();
void matrixB();
void multiply();
void validityCheck();
//declare variables
int arrayB[100][100];
int i,j,num,k=1;
//matrix B variables
int arrayA[100][100];
int row,col,numb=1;
int sum;

int main()
{
matrixA();
matrixB();
multiply();
}

/*------------------------------My Functions----------------------------*/

void matrixA()
{

//creates first matrix

cout<< "Matrix A "<<endl;

for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
arrayA[i][j]=num;
num=num+1;
}
}

for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
cout.width(5);
cout<<arrayA[i][j];
}
cout << endl;
}
cout<<"                                                   "<<endl;

}

void matrixB()
{

//creates second matrix

cout<< "Matrix B"<<endl;

for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
arrayB[i][j]=num;
num=num+1;
}
}

for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
cout.width(5);
cout<<arrayB[i][j];
}
cout << endl;
}
}

void multiply()
{

for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{

for(k=1;k<=2;k++)
{
sum=sum+(arrayA[i][k]*arrayB[k][j]);
}
cout<<sum<<" sum "<<endl;
sum=0;

}

}

}```

2. Code:
```void multiply()
{
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
for(k=1;k<=2;k++)
{
sum=sum+(arrayA[i][k]*arrayB[k][j]);
}

cout<<sum<<" sum "<<endl;
sum=0;
}
}
}```
1) Are you aware that arrays have zero based indexes, i.e. they start at index 0? The rows start at index 0, and the columns in every row start at index 0. You are skipping the entire first row of a matrix as well as the first spot in every row, which is a waste of memory--although only a tiny bit is wasted.

2) You don't need three for-loops to multiply a couple of 2 x 2 matrices together--you should only need two for-loops. I assume you want to multiply each value in one matrix by the value in the same spot in the other matrix. Let's take a look at what your three loops do:
Code:
```i=1
j=1
k=1
arrayA[1,1] * arrayB[1,1] //ok
k=2
arrayA[1,2] * arrayB[2,1] //??
j=2
k=1
arrayA[1,1] * arrayB[1,2] //??
k=2
arrayA[1,2] * arrayB[2,2] //??

i=2
etc., etc.```
Is that what you want?

3) To output an array to look like a matrix, in your case, use two for-loops. The outer loop will specify the row, and the inner loop will specify the column in the row. You can use cout in the inner loop to output the value at that position, and follow it with a space: " ". Just after the closing bracket of the inner for loop, which is before the outer loop has a chance to increment the row, use cout to start a newline: cout<<endl;

3. ???????
Code:
```int c[100][100];
for(int i = 0; i < 100; i++)
for(int j = 0; j < 100; j++)
c[i][j] = a[i][j] * b[i][j];```