-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2cl.cpp
49 lines (44 loc) · 1.2 KB
/
p2cl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Modul Praktikum GP2103 Metode Komputasi,
Program Studi Teknik Geofisika, Universitas Pertamina
Oleh: Hardianto Rizky Prabusetyo dan Mohammad Heriyanto
Website: https://osf.io/5tfvq/
Link Kode: https://github.com/Metkom/Kode-Praktikum-GP2103-Metode-Komputasi
DOI: 10.17605/OSF.IO/5TFVQ
@ Oktober 2017
*/
#include<iostream>
using namespace std;
int main(){
int i,j,r=3,c=3;
int mat[r][c];
float det=0.0;
cout<<"Masukkan matriks 3x3:\n";
for(i=0;i<3;i++){
for(j=0;j<3;j++){
cin>>mat[i][j];
}
}
printf("\nMatriks yang diinput:");
for(i=0;i<3;i++){
cout<<"\n";
for(j=0;j<3;j++){
cout<<mat[i][j]<<"\t";
}
}
// menghitung determinan matriks
for(i=0;i<3;i++){
det=det+(mat[0][i]*(mat[1][(i+1)%3]*\
mat[2][(i+2)%3]-mat[1][(i+2)%3]*mat[2][(i+1)%3]));
}
cout<<"\n\nDeterminan: "<<det;
// menghitung inversi matriks
cout<<"\n\nInversi matriknya: \n";
for(i=0; i < 3; i++){
for(j = 0; j < 3; j++){
cout<<((mat[(j+1)%3][(i+1)%3]*\
mat[(j+2)%3][(i+2)%3])-(mat[(j+1)%3][(i+2)%3]*\
mat[(j+2)%3][(i+1)%3]))/det<<"\t";
}cout<<"\n";
}
return 0;
}