1.

Write a program to multiply two 2-D matrices of size 3x3.

Answer»

# include <iostream.h>

void main( )

{

int a[3] [3], b[3] [3], mult [3] [3], i,

j, k;

cout << "Enter elements of matrix 1"

<< endl;

for(i = 0; i <3;i++)

for(j = 0; j <3; j++)

{

cout << "Enter element at position" <<

i + 1 << j + 1 << " : ";

cin >> a[i] [j];

}

cout << "Enter elements of matrix 1"

<< endl;

for(i = 0; i <3;i++)

for(j = 0; j <3; j++)

{

cout << "Enter element at position" <<

i + 1 << j + 1 << " : ";

cin >> b[i][j];

}

for(i = 0; i <3;i++)

for(j = 0; j <3; j++)

{

mult [i] [j] =0;

}

// Multiplying matrix a and b and

storing in array mult.

for(i = 0; i <3;i++)

for(j = 0; j <3; j++)

for(k = 0; k < 3; k++)

{

mult[i] [j] += a[i] [k] * b[k] [j];

}

cout << endl << "Output Matrix: " <<

endl;

for(i = 0; i <3;i++)

{ for(j = 0; j <3; j++)

{

cout << " " << mult[i][j];

} cout << endl;

}

}



Discussion

No Comment Found

Related InterviewSolutions