How to write with pointers?
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 67 68 69 70 71 72 73 74 75 76 77
|
#include<iostream>
using namespace std;
int main()
{
int a[10][10], b[10][10], c[10][10];
int n, i, j;
n = 2;
cout << "\nNumber of rows in matrix A:" << n << endl;
cout << "\nNumber of columns in matrix A:" << n << endl;
cout << "\n\nEnter elements for Matrix A :::\n\n";
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
cin >> a[i][j];
}
cout << "\n";
}
cout << "\n\nMatrix A :\n\n";
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
cout << "\t" << a[i][j];
}
cout << "\n\n";
}
cout << "\n-------------------------------------------\n";
cout << "\nNumber of rows in matrix B:" << n << endl;
cout << "\nNumber of columns in matrix B:" << n << endl;
cout << "\n\nEnter elements for Matrix B :::\n\n";
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
cin >> b[i][j];
}
cout << "\n";
}
cout << "\n\nMatrix B :\n\n";
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
cout << "\t" << b[i][j];
}
cout << "\n\n";
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
c[i][j] = 0;
for (int k = 0; k < n; k++)
{
c[i][j] = c[i][j] + a[i][k] * b[k][j];
}
}
}
cout
<< "\n-----------------------------------------------------------\n";
cout << "\n\nMultiplication of Matrix A and Matrix B :\n\n";
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
cout << "\t" << c[i][j];
}
cout << "\n\n";
}
return 0;
}
|
Last edited on
Is the above program correct?
What is your program all about?
Write a C++ program to multiply two order matrices
What does 'order matrix' mean?
What is your original assignment?
Original assignment: Write a C++ program to multiply any two order matrix with pointers.
Order of matrix: Number of rows and columns in it.
Two order matrix : has two rows and two columns.