latest Post

Perkalian matriks dengan C++

Berikut contoh program perkalian matriks dengan menggunakan Dev-C++

#include <iostream>
using namespace std;
int main()
{
	int A[3][3]={{6,7,8},{1,2,3},{3,4,5}};
	int B[3][3]={{4,2,3},{5,3,7},{3,4,6}};
	int C[3][3]; 
	
	cout<<"Matriks A "<<endl;
	cout<<A[0][0]<<" "<<A [0][1]<<" "<<A[0][2]<<endl;
	cout<<A[1][0]<<" "<<A [1][1]<<" "<<A[1][2]<<endl;
	cout<<A[2][0]<<" "<<A [2][1]<<" "<<A[2][2]<<endl;
	cout<<endl;
	
	cout<<"Matriks B "<<endl;
	cout<<B[0][0]<<" "<<B [0][1]<<" "<< B[0][2]<<endl;
	cout<<B[1][0]<<" "<<B [1][1]<<" "<< B[1][2]<<endl;
	cout<<B[2][0]<<" "<<B [2][1]<<" "<< B[2][2]<<endl;
	
	cout<<endl;
	cout<<"Matriks A dikalikan Matriks B"<<endl;
	for (int a=0;a<3;a++){
		for (int b=0;b<3;b++){
			C[a][b]=(A[a][0]*B[0][b])+(A[a][1]*B[1][b])+(A[a][2]*B[2][b]);
		}
	}
	for (int a=0;a<3;a++){
		for (int b=0;b<3;b++){
			cout<<"Matriks C"<<endl;
				cout<<C[0][0]<<" "<<C [0][1]<<" "<< C[0][2]<<endl;
				cout<<C[1][0]<<" "<<C [1][1]<<" "<< C[1][2]<<endl;
				cout<<C[2][0]<<" "<<C [2][1]<<" "<< C[2][2]<<endl;
		}
	}
	return 0;
}

About Unknown

Unknown
Recommended Posts × +

0 comments:

Post a Comment