Tugas operator matriks
// notasi
// judul : operator matriks
// kamus
MatA[4][3],MatB[4][3],MatC[4][3],MatD[4][3] array of integer
x,y,z <== integer
// deskripsi
output " input matriks A "
x = 0
while(x < 4)
y=0
do
input MatA[y][x]
y = y +1
while(y < 3)
x = x+1
output "menampilkan matriks A "
x = 0
while(x < 3)
y=0
while(y < 4)
output MatA[y][x]
y = y +1
x = x+1
// matB
output "input matriks B "
z=0
do
x=0
while(x <4)
input MatB[x][z]
x =x +1
z = z +1
while(z <3)
output "menampilkan Matriks B"
y=0
while(y <3) do
z = 0
do
output MatB[z][y]
z = z+1
while(z < 4)
y = y +1;
// input MatC
cout " input mat c"
z=0
while(z < 3)
y = 0
while(y < 4)
input MatC[y][z]
y = y +1
z = z+1
putput " menampilkan MatC"
x = 0
do
z = 0
while(z < 4)
output MatC[z][x]
z = z+1
x = x+1
while(x < 3)
// operator matD
ouput " menampilkan hasil dari matriks (a+b) - (a+c)
x = 0
while(x < 3)
y = 0
do
MatD[y][x] = (MatA[y][x] + MatB[y][x]) - (MatA[y][x] + MatC[y][x])
y = y +1
while(y < 4)
x = x+1
/// hasil
output " hasilnya adalah "
y =0
do
z = 0
while( z < 4)
output MatD[z][y]
z = z+1;
y = y +1
while(y <3)
// source code
// penambahan matriks jika berkolom
#include <iostream>
using namespace std;
// kamus
int MatA[4][3],MatB[4][3],MatC[4][3],MatD[4][3];
int x,y,z;
//deskripsi
int main()
{
// menginputkan matriks A
cout << " menampilkan Matriks A dengan nilai 2 3 4 1 I 2 4 1 6 I 8 1 1 7" << endl;
x = 0;
while(x < 3)
{
y = 0;
do
{
cout << " input kolom ke " << x << " input baris ke " << y << " ";
cin>> MatA[y][x];
y = y +1;
}while(y < 4);
x = x +1;
}
//menampilkan matriks A
cout << endl;
cout << " menampilkan Matriks A " << endl;
x = 0;
while(x < 3)
{
y = 0;
while(y < 4)
{
cout << MatA[y][x] << " ";
y = y +1;
}
cout << endl;
x = x +1;
}
cout << endl;
//menginputkan matriks B
cout << " menampilkan Matriks B 4 4 9 1 I 1 7 3 1 I 3 3 1 2" << endl;
z =0;
do
{
x=0;
while(x < 4)
{
cout << " input kolom ke " << z << " input baris ke " << x << " ";
cin >> MatB[x][z];
x = x +1;
}
z = z+1;
}while(z < 3);
//menampilkan matriks B
cout << endl;
cout << "menampilkan Matriks B " <<endl;
y=0;
while(y <3)
{
z = 0;
do
{
cout << MatB[z][y] << " ";
z = z+1;
}while(z < 4);
cout << endl;
y = y +1;
}
//menginputkan matriks C
cout << " manampilak Matriks C dengan nilai 4 7 9 1 I 1 7 3 1 I 3 3 1 2" << endl;
z=0;
while(z < 3)
{
y = 0;
while(y < 4)
{
cout << " input kolom ke " << z << " input baris ke " << y << " ";
cin >> MatC[y][z];
y = y +1;
}
z = z+1;
}
// menampilkan matriks C
cout << " menampilkan matriks C " << endl ;
x = 0;
do
{
z = 0;
while(z < 4)
{
cout << MatC[z][x] << " " ;
z = z+1;
}
cout << endl;
x = x+1;
}while(x < 3);
// menghitung
cout << " menghitung Matriks (A+B) - (A-C) " <<endl;
x = 0;
while(x < 3)
{
y = 0;
do
{
MatD[y][x] = (MatA[y][x] + MatB[y][x]) - (MatA[y][x] + MatC[y][x]);
y = y +1;
}while(y < 4);
x = x+1;
}
cout << "hasil nya adalah " << endl;
y =0;
do
{
z = 0;
while( z < 4)
{
cout << MatD[z][y] << " ";
z = z+1;
}
cout << endl;
y = y +1;
}while(y <3);
}
// output
Comments
Post a Comment