es funktioniert jetzt. anstelle von int musste ich double nehmen.
jetzt habe ich folgenden code:
#include <iostream>
using namespace std;
int main()
{
int n, m, l;
double **matA, **matB;
double **matC=0;
cout<<"Gebe n ein ";
cin>>n;
cout<<"Gebe m ein ";
cin>>m;
cout<<"Gebe l ein ";
cin>>l;
// ************************Matrix A:************
matA= new double *[n];
for(int i=0;i<n;i++)
{
*(matA+i)=new double[m];
}
for(int j=0;j<n;j++)
{
for(int q=0;q<m;q++)
{ cout<<"A: Bitte geben Sie eine Zahl ein"<<endl;
cin>>*(*(matA+j)+q);
}
}
//Ausgabe MatA:
for (int i=0; i<n; i++)
{ for (int k=0; k<m; k++)
{cout<<*(*(matA+i)+k);}
cout<<endl;
}
// **************Matrix B:**********************
matB= new double *[m];
for(int i=0;i<m;i++)
{
*(matB+i)=new double[l];
}
for(int j=0;j<m;j++)
{
for(int q=0;q<l;q++)
{ cout<<"B: Bitte geben Sie eine Zahl ein"<<endl;
cin>>*(*(matB+j)+q);
}
}
// Ausgabe MatB:
for (int i=0; i<n; i++)
{ for (int k=0; k<m; k++)
{cout<<*(*(matB+i)+k);}
cout<<endl;
}
//******************Matrix C:*********************
matC= new double *[n];
for(int i=0;i<n;i++)
{
*(matC+i)=new double[l];
}
//******************Multiplikation**********
for (int i=0; i<n; i++)
{ for (int j=0; j<l; j++)
{for (int k=0; k<m; k++)
{*(*(matC+i)+j)+=*(*(matA+i)+k)*(*(*(matB+k)+j));}
}
}
//***************Ausgabe matC*********************
cout<<"Das Ergebnis ist:\n";
for (int i=0; i<n; i++)
{for (int j=0; j<l; j++)
{cout<<*(*(matC+i)+j)<<" ";}
cout<<endl;
}
}
ich möchte jetzt aber die multiplikation in einer eigenen funktion tun, aber ich weiß nicht wie. muss die funktion void oder int sein? und sind 2 mal "*" richtig?
hab das schon:
void multi (double **matA, double **matB, double **matC, int n, int m, int l)
{ for (int i=0; i<n; i++)
{ for (int j=0; j<l; j++)
{for (int k=0; k<m; k++)
{*(*(matC+i)+j)+=*(*(matA+i)+k)*(*(*(matB+k)+j));}
}
}
}
aber ich weiß nicht wie ich das in main einbinde. habe auch eine header datei, die ich in main einfüge mit #include "multi.h":
# ifndef MULTI_H
# define MULTI_H
double multi (double **matA, double **matB, double **matC, int n, int m, int l);
#endif
jetzt weiß ich nicht wie ich in main das ergebnis ausbringe