Skip to content

Mengubah Matriks Menjadi Segitiga Atas C++

Coba iseng-iseng upload tugas Aljabar Linear kemaren ‘Sekalian ngetest plugin masukin source code ke postingan’, karena tugasnya ya rumayan muter muter :v
Jadi ya tugas ini, terserah input matriksnya mau ordo3x3 ordo4x4 dan seterusnya, lalu matriks tersebut dirubah menjadi matriks segitiga atas , kemudian langkah terakhir mencari determinan matriks tersebut dengan bahasa pemrograman c++.

[codesyntax lang=”cpp” lines=”normal”]

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
	int a;
	double ichwan;
	cout<<"Masukkan ukuran matriks : "; cin>>a;
	double matriks [a][a];
	//Menginput Matriks dan Menampilkannya
	for (int x=0;x<a;x++){
		for (int y=0;y<a;y++){
			cout<<"["<<x<<"]"<<"["<<y<<"]";
			cin>>matriks[x][y];}}
			cout<<endl;
	for (int x=0;x<a;x++){
		for (int y=0;y<a;y++){
			cout<<matriks[x][y]<<" ";}
		cout<<endl;}
		system("pause");
                cout<<endl;
	//Membuat Matriks Menjadi Matriks Segitiga Atas
	for(int i=0;i<a-1;i++){
        for(int j=i+1;j<a;j++){
            ichwan=matriks[j][i]/matriks[i][i];
            for(int k=i;k<a;k++){
                matriks[j][k]=matriks[j][k]-(ichwan*matriks[i][k]);
                for(int p=0;p<a;p++){
                    for (int r=0;r<a;r++){
                        cout<<matriks[p][r]<<" ";
                    } cout <<endl;
                } cout<<endl;
            system("pause");
			}
        }
    }
	//Menghitung Determinan Matriks
	double hasil=1;
	for (int x=0;x<a;x++){
		hasil=hasil*matriks[x][x];}
		cout<<"Determinan = "<<hasil;
		getch();
}

[/codesyntax]

4 Comments

  1. katnis everdeen katnis everdeen

    makasih chwandd 🙂

      • Perhaps it is Jah&9–tmeree#3s;s a lot of support for that calibre. But the whole thing is complicated by career brass who staked so much on the 5.56 and the sheer cost of change.Add classic military inertia to that.;)

  2. Rendy Rendy

    bang kalau matrixnya membaca dari file txt kodingnya gmn bang tolong dong

Leave a Reply

Your email address will not be published. Required fields are marked *