Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Matrizenaddition - Hilfe Probleme mit dem Code

Empfohlene Antworten

Hallo Leute!

Ich habe ein riesiges Problem!Hab einen Code geschrieben der mir die Matrizen zusammen zählen soll. Tut er natürlich nicht, anscheinend bin ich ned gut genug bei der Sache und habe auch keine Lust mehr drauf. Könnt ihr mir helfen?

Das ist mein Code:

//Addieren zweier Matrizen


#include <iostream>

#include <stdlib.h>


using namespace std;



const int dim=1;

typedef float matrixtyp [dim][dim];


void liesMatrix (matrixtyp ,matrixtyp, int );

void addmatrix (const matrixtyp , const matrixtyp, matrixtyp , int );

void schreibMatrix (const matrixtyp, int);


int main () 

{	

	matrixtyp A;

	matrixtyp B;

	matrixtyp C;



	liesMatrix ( A,B, dim);

	addmatrix ( A, B, C, dim);

	schreibMatrix ( A, dim);


system ("pause");

return 0;

}


//Einlesen zweier Matrizen


void liesMatrix (matrixtyp A,matrixtyp B, int dim)

{

	for (int i=0; i<dim; i++)

	{

		cout<<"Zeile"<<i+1<<": ";

		for (int j=0; j<dim; j++)

			cin>>A[i][j];

	}

	for (int k=0; k<dim; k++)

	{

		cout<<"Zeile"<<k+1<<": ";

		for (int d=0; d<dim; d++)

			cin>>B[k][d];

	}

}


//Addieren zweier Matrizen


void addmatrix (const matrixtyp A, const matrixtyp B, matrixtyp C, int dim)

{

	float summe;

	for (int i=0; i<dim; i++)

		for (int j=0; j<dim;j++)

	{

		summe=0;

		for ( int k=0; k<dim; k++)	//Matrizenaddition

			summe += A[i][k]+B[k][j];

			C[i][j]=summe;

	}


}


//Ausgeben einer Matrix


void schreibMatrix (const matrixtyp C, int dim)

{

	for (int i=0; i<dim; i++)

	{ for (int j=0; j<dim; j++)

		cout<<C [i][j];

		cout<<endl;

	}

}

Ich danke euch für die Ausbesserungen und Vorschläge und natürlich für jeden einzelnen Tipp. THX an alle Beteiligten.

Tut er natürlich nicht, anscheinend bin ich ned gut genug bei der Sache und habe auch keine Lust mehr drauf.
Das ist keine besonders gute Problembeschreibung.

Mir fällt auf jeden Fall auf, dass du die Ergebnisse nicht einfach so "by value" übergeben darfst, weil sich Änderungen an diesen Parametern nicht auf die Variablen auswirken, mit denen du die Funktionen aufgerufen hast. Das sollten also schon Referenzen sein.

Tut er natürlich nicht
Das ist keine besonders gute Problembeschreibung.

Mir fällt auf jeden Fall auf, dass du die Ergebnisse nicht einfach so "by value" übergeben darfst, weil sich Änderungen an diesen Parametern nicht auf die Variablen auswirken, mit denen du die Funktionen aufgerufen hast. Das sollten also schon Referenzen sein.

Danke für den Tipp, hab schon selber was entdeckt aber nicht das was du vorgeschlagen hast. Danke werde mal versuchen was damit anzustellen.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Konto

Navigation

Suchen

Suchen

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.