write a program that will multiply two dimentional arrays as follow:

1. The program should prompt the user for the dimention of the first array (row x coloum).
2. The program should get the values of the first array one by one. (e.g. program should display "enter value of a[1][1]= , ...etc"
3. The program should prompt the user for the dimention of the second array.
4. If the dimention of the second array is not compatible with the first array (can not multiply with), then refuse to accept the second array and ask the user again for the dimention of the second array.

5. The program should get the values of the second array one by one.
6. The program should calculate the multiplication and store the result in third matrix (array)
7. The program should print the result of the multiplication in an organized way.

Notice that this program is to be used by students taking the course MATH 111, and they do not know Cpp, hence you should ask them to enter values starting from 1 to n not from 0 to n-1 in the arrary, and you should store them in locations from 0 to n-1 in your program, but the user should not notice this.

Recommended Answers

All 5 Replies

Start with task #1. When you can do that then try doing task #2. When you can do that then try #3. Don't think of the whole program all at once. Once you have both matrixes, then the code to set up the actual multiplication, task #6 can be done. It's been a while since I set up a matrix multiplication but if you have trouble and I don't respond I'm sure some one else will.

cheers

can anyone write the full program ?

i'm writing only the main part
void main()
{
int a[10][10], b[10][10],i,j,k n,m,s;
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
cin>>a[j];
}
}

cin>>m;
for(i=1;i<=m;i++)
{
for(j=1;j<m;j++)
{
cin>>b[j];
}
}
if(m!=n)

exit();
else
{

for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
c[j]=0;
for(k=1;k<=n;k++)
c[j]=a[k]*b[k][j]+c[j];
}
}
}
now output c[j];

11 ERRORS

can anyone write the full program ?

You're supposed to show an attempt, and corrections and suggestions would then be offered.

11 ERRORS

How rude. You make no attempt and then complain about a gift? Why don't you take a pop at correcting the errors and start trying to do your own homework?

Besides the syntax errors, also be aware of this:

void main()

Don't do void main() -- use a proper int main().

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

Arrays are zero-based. Adjust the initialization and loop condition accordingly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.