So i am writing a simple prgm in which you enter the values of 2 matrices and multiplies them.

``````#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main() {
int i, j , k , l, m , n , o, p;
cout<<"Enter The Rows And Cloumns And Of The First Matrix:";
cin>>m>>n;
cout<<"Enter The Rows And Cloumns And Of The Second Matrix:";
cin>>o>>p;
if ( n != o ) {
cout << "can't do" << endl;
return 0 ; }

else {

cout<<"\nEnter Elements Of The First Matrix:\n";
int a[m][n];

for(i=0;i<m;i++)
{
for(j=0;j< n;j++)
{
cin>>a[i][j];
}
}
cout<<"\nEnter Elements Of The Second Matrix:\n";
int b[o][p];
for(j=0;j<o;j++)
{
for(k=0;k<p;k++)
{
cin>>b[j][k];
}
}

int c[m][p];
for (int i = 0; i < m; i++) {
for (int k = 0; k< p; k++) {
double s = 0;
for (int j = 0; j < o; j++) {
s += a[i][j] * b[j][k];
}
c[m][p] = s;

}	cout << "The answer is "  ;
cout <<c ; }}}``````

but whenever i compile it i get this

``The answer is 0xbffff610The answer is 0xbffff610The answer is 0xbffff610``

any suggestions?

So i am writing a simple prgm in which you enter the values of 2 matrices and multiplies them.

``````#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main() {
int i, j , k , l, m , n , o, p;
cout<<"Enter The Rows And Cloumns And Of The First Matrix:";
cin>>m>>n;
cout<<"Enter The Rows And Cloumns And Of The Second Matrix:";
cin>>o>>p;
if ( n != o ) {
cout << "can't do" << endl;
return 0 ; }

else {

cout<<"\nEnter Elements Of The First Matrix:\n";
int a[m][n];

for(i=0;i<m;i++)
{
for(j=0;j< n;j++)
{
cin>>a[i][j];
}
}
cout<<"\nEnter Elements Of The Second Matrix:\n";
int b[o][p];
for(j=0;j<o;j++)
{
for(k=0;k<p;k++)
{
cin>>b[j][k];
}
}

int c[m][p];
for (int i = 0; i < m; i++) {
for (int k = 0; k< p; k++) {
double s = 0;
for (int j = 0; j < o; j++) {
s += a[i][j] * b[j][k];
}
c[m][p] = s;

}	cout << "The answer is "  ;
cout <<c ; }}}``````

but whenever i compile it i get this

``The answer is 0xbffff610The answer is 0xbffff610The answer is 0xbffff610``

any suggestions?

Well at line
cout << c;

the operator << is not overloaded for arrays
What c++ see is just a memory place and prints it out
You should do something like that instead

``````for(i = 0  ; i <  i_max; i++){
for(j = 0 ;  j <  j_max ; j++)
cout<<c[i][j]<<" ";
cout<<endl;
}``````

where i_max is the maximum for lines
and j_max is the maximum for columns.

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.