Zum Inhalt springen

kathrin1986

Mitglieder
  • Gesamte Inhalte

    9
  • Benutzer seit

  • Letzter Besuch

  1. was muss ich denn genau dann schreiben? ich verstehe das nicht so wirklich.
  2. das mit den strukturen funktioniert jetzt. ich will die multiplikation jetzt aber in eine eigene funktion packen. das funktioniert aber nicht. die funktion sieht so aus: void multi (double **matA, double **matB, double **matC, int zeileA, int spalteB, int spalteA) { for (int i=0; i<zeileA; i++) { for (int j=0; j<spalteB; j++) {for (int k=0; k<spalteA; k++) {matC.mat[i][j]+=matA.mat[i][k]*(matB.mat[k][j]);} } } } als fehlermeldung in zeile 7 kommt 3mal :"links von .mat muss eine struktur sein" später will ich die funktion im main einbinden dazu nutze ich diesen code: multi (matA, matB, matC, zeileA, spalteB, spalteA); da kommt als fehlermeldung: "Multi: Konvertierung des Parameters 1 von Matrix in double ** nicht möglich. was ist denn falsch daran?
  3. habe jetzt drei strukturen angelegt. aber es funktioniert nicht. es kommt immer die zahl -627744e+066 raus. die ausgabe von MatA und MatB ist richtig. also muss was in MatC oder in der Rechnung falsch sein. ich weiß aber nicht wo. habe folgenden code #include <iostream> using namespace std; struct MatA { int zeileA; int spalteA; double **matA; }; struct MatB { int zeileB; int spalteB; double **matB; }; struct MatC { int zeileC; int spalteC; double **matC; }; void main() { int zeileA, spalteA; int zeileB, spalteB; MatA matA; MatB matB; MatC matC; cout<<"Gebe n ein: \n"; cin>> zeileA; cout<<"Gebe m ein \n"; cin>> spalteA; cout<<"Gebe l ein \n"; cin>>spalteB; // ************Matrix A:****************** (matA).zeileA=zeileA; (matA).spalteA=spalteA; (matA).matA=new double *[zeileA]; for (int i=0; i<zeileA; i++) {matA.matA[i]=new double[spalteA]; } for (int i=0; i<matA.zeileA; i++) { for (int j=0; j<matA.spalteA; j++) {cout<<"A:Bitte geben Sie eine Zahl ein"<<endl; cin>>matA.matA[i][j]; }} // Ausgabe MatA: for (int i=0; i<matA.zeileA; i++) { for (int j=0; j<matA.spalteA; j++) {cout<<matA.matA[i][j]<<" ";} cout<<endl; } //************Matrix B**************** (matB).zeileB=spalteA; (matB).spalteB=spalteB; (matB).matB=new double *[spalteA]; for (int i=0; i<spalteA; i++) {matB.matB[i]=new double[spalteB]; } for (int i=0; i<matA.spalteA; i++) { for (int j=0; j<matB.spalteB; j++) {cout<<"B: Bitte geben Sie eine Zahl ein"<<endl; cin>>matB.matB[i][j]; }} //Ausgabe MatB: for (int i=0; i<matA.spalteA; i++) { for (int j=0; j<matB.spalteB; j++) {cout<<matB.matB[i][j]<<" ";} cout<<endl; } //*************Matrix C*************** (matC).zeileC=zeileA; (matC).spalteC=spalteB; (matC).matC=new double *[zeileA]; for (int i=0; i<zeileA; i++) {matC.matC[i]=new double[spalteB]; } //*************Multiplikation************ for (int i=0; i<zeileA; i++) { for (int j=0; j<spalteB; j++) {for (int k=0; k<spalteA; k++) {matC.matC[i][j]+=matA.matA[i][k]*(matB.matB[k][j]);} } } //**********Ausgabe************ cout<<"Das Ergebnis ist:\n"; for (int i=0; i<zeileA; i++) {for (int j=0; j<spalteB; j++) {cout<<matC.matC[i][j]<<" ";} cout<<endl; } } oder ist was in der ausgabe von MatC falsch?
  4. ich will die multiplikation zweier matrizen jetzt mit einer struktur machen, komme aber nicht weiter. brauche ich dafür drei strukturen? für jede matrix eine? oder wie geht das jetzt mit matrix b? das hab ich schon: #include <iostream> using namespace std; struct Matrix { int zeile; int spalte; double **mat; }; void main() { int zeile, spalte; Matrix &mat; cin>> zeile; cin>> spalte; // ************Matrix A:****************** (mat).zeile=zeile; (mat).spalte=spalte; (mat).mat=new double *[zeile]; for (int i=0; i<zeile; i++) {mat.mat[i]=new double[spalte]; } for (int i=0; i<mat.zeile; i++) { for (int j=0; j<mat.spalte; j++) {cout<<"Bitte geben Sie eine Zahl ein"<<endl; cin>>mat.mat[i][j]; }} //************Matrix B**************** } wie geht das jetzt für matrix b?
  5. danke, es funktioniert jetzt auch mit der funktion:)
  6. 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
  7. was muss ich denn machen um sie zu initialisieren?
  8. Hi, ich möchte zwei Matrizen multiplizieren. Habe dazu Zeiger benutzt. bei mir werden keine Fehler angezeigt, aber das ergebnis der multiplikation ist immer -84215.... ich weiß nicht wo mein fehler liegt, vielleicht kann mir jemand helfen. mein code: #include <iostream> using namespace std; int main() { int n, m, l; int **matA, **matB, **matC; cout<<"Gebe n ein "; cin>>n; cout<<"Gebe m ein "; cin>>m; cout<<"Gebe l ein "; cin>>l; // ************************Matrix A:*********** matA= new int *[n]; for(int i=0;i<n;i++) { *(matA+i)=new int[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 int *[m]; for(int i=0;i<m;i++) { *(matB+i)=new int[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 int *[n]; for(int i=0;i<n;i++) { *(matC+i)=new int[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********************* for (int i=0; i<n; i++) {for (int j=0; j<l; j++) {cout<<"Das Ergebnis ist:"<< *(*(matC+i)+j);} } }

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...