3x3 matrix mit sarrus

joan283

Grünschnabel
Hi!

Ich hab da son kleines Problem: ich soll da son prog schreiben und hab keine ahnung vom programmieren :)

und zwar soll es ein prog sein, bei dem man ne 3x3 matrix hat und mit dem Sarrus-Schema die Determinante bestimmen soll.die ersten beiden spalten sollen also hinter der dritten reihe wiederholt werden und haupt- und nebendiagonale werden multipliziert und dann von einander abgezogen.
das mathematische kann ich ja auch, aber das in nen programm umzustricken is irgendwie nich möglich --- also für mich :) bin da voll hohl ;)

wäre also nett, wenn mit jemand helfen kann.

mfg Joan
 
moin


Was ist denn genau dein Problem?
Wie weit ist dein Programm schon? Poste es mal.

Und beachte bitte in Zukunft die Groß und Kleinschreibung.


mfg
umbrasaxum
 
Mein Problem ist die komplette Aufgabenstellung.
Ich weiß gerade noch, wie ich mit dem Programm anfangen muss und das hier is das, was ich bis jetzt habe:
 
#include <iostream.h>
#include <iomanip.h>
int main(void)

{
int mat [3][3];
int zeile, spalte;

//Beschreiben der Matrix

for (zeile = 0; zeile < 3; zeile++)
for(spalte =0; spalte < 3; spalte++)
mat [zeile][spalte] = 10 *zeile + spalte;

//Ausgabe

for (zeile =0; zeile < 3;zeile++)
{
for (spalte=0; spalte < 3;spalte++)
cout<< setw(5) <<mat[zeile][spalte];
cout<< endl;
}
cout<<endl<<endl;


return 0;
}
 
Hallo!

Schau mal hier:
Code:
// sarrus.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//

#include "stdafx.h"
#include <iostream.h>

int _tmain(int argc, _TCHAR* argv[])
{

	const int n = 3;
	const int m = 5;
	int matrix[n][m];
	int v[] = {2,1,6,0,4,2,0,0,3};
	for(int i = 0; i< n;i++){
		for(int j= 0; j < m;j++){
			if(j < 3){
				matrix[i][j] = v[i*3+j];
			}else{
				matrix[i][j] = matrix[i][j%2];
			}
		}
	}

	//Ausgabe
	for(int i = 0; i< n;i++){
		for(int j= 0; j < m;j++){
			cout << matrix[i][j] << "\t";
		}
		cout << endl;
	}

	int detMatrix = matrix[0][0]*matrix[1][1]*matrix[2][2]+
					matrix[0][1]*matrix[1][2]*matrix[2][0]+
					matrix[0][2]*matrix[1][0]*matrix[2][1]
					- matrix[0][2]*matrix[1][1]*matrix[2][0]
					- matrix[0][0]*matrix[1][2]*matrix[2][1]
					- matrix[0][1]*matrix[1][0]*matrix[2][2];

	cout << "det(m) = " << detMatrix << endl;
	
	return 0;
}

Ausgabe:
Code:
2       1       6       1       2
0       4       2       4       0
0       0       3       0       0
det(m) = 24

Gruß Tom
 
nee leider nich Diplstress, is einfach nur ne Prüfungsverleistung mache eigentlich Maschbau und hab den Kram nur dieses Semester.... zum Glück
 
es funxt! *freu*
Werde das mit der Eingabe mal selbst probieren :)
Aber ich werd das wohl hinkriegen ---- hoffe ich mal

DANKE
 

Neue Beiträge

Zurück