Menghitung vektor 2 elemen, Matrix 2x3 dan Vektor 3 elemen
2.)Menentukan Input dan Output
Input
matrix [2][3]={1,2,3,4,5,6}
vektor [2]={7,6}
vektor [3]={10,9,8}
Output
matrix 2x3 dengan vektor 3 elemen
53
133
Hasil matrix 2x3, vektor 3 elemen dan vektor 2 elemen
364
748
3.) Membuat Algoritma atau Flowchart
Deklarasi :
matrix[2][3]={1,2,3,4,5,6}
vektor[2]={7,6}
vektor[3]={10,9,8}
Deskripsi
write('Matrix 2x3 : \n') for i ß 0 to 2 do then c++ for j ß 0 to 3 then j++ hasil[a] ß hasil[c]+(matrix[c][b]*vektor[b]); end for end for for a ß 0 to 2 do then a++ for b ß 0 to 3 then b++ then write(hasil[a][b]) end for end for write(‘vektor 3 elemen: \n’) for b ß 0 to 3 then b++ then write(vektor[a]) end for write(‘vektor 2 elemen : \n’) for a ß 0 to 2 then a++ then write(vek[a]) end for write(‘Matrix 2x3 dan vektor 3 elemen : \n’) for a ß 0 to 2 then a++ write(hasil[a]) end for write(‘Matrix 2x3, vektor 2 elemen dan vektor 3 elemen : \n’) for a ß 0 to 2 then a++ hasil[i] ßhasil[a]*vek[a]; write(hasil[a]) end fo
4.) Menggunakan data
Input :
matrix [2][3]= |1 2 3|
|4 5 6|
vektor [2]= |7|
|6|
vektor [3]= |10|
| 9 |
| 8 |
Output :
Matrix 2x3 dan vektor 3 elemen : 52
133
Matrix 2x3, vektor 3 elemen dan vektor 2 elemen : 364
798
5.) C++
#include <iostream>
using namespace std;
void kcli(int mctrix[2][3],int vektor[3],int hcsil[2]){
cout<<"Matrix 2x3 "<<endl;
for(int c=0;c<2;c++){
for(int z=0;z<3;z++)
hcsil[c]=hcsil[c]+(mctrix[c][z]*vektor[z]);
}
}
void cetcktrix(int hcsil[][3]){
for(int c=0;c<2;c++){
for(int z=0;z<3;z++)
cout<<hcsil[c][z]<<" ";
cout<<endl;
}
}
void cetcktor(int vektor[]){
cout<<"Vektor 3 Elemen "<<endl;
for(int c=0;c<3;c++){
cout<<vektor[c]<<endl;
}
}
void cetckzcr(int vek[]){
cout<<"Vektor 2 Elemen "<<endl;
for(int c=0;c<2;c++){
cout<<vek[c]<<endl;
}
}
void cetck(int hcsil[]){
cout<<"Matrix 2x3 dengan Vektor 3 elemen "<<endl;
for(int c=0;c<2;c++){
cout<<hcsil[c]<<endl;
}
}
void cetckc(int vek[2],int hcsil[]){
cout<<"Hasil akhir"<<endl;
for(int c=0;c<2;c++){
hcsil[c]=hcsil[c]*vek[c];
cout<<hcsil[c]<<endl;
}
}
int main() {
int mctrix[2][3]={1,2,3,4,5,6}, vektor[3]={10,9,8},vek[2]={7,6},hcsil[2]={0};
kcli(mctrix,vektor,hcsil);
cetcktrix(mctrix);
cetcktor(vektor);
cetck(hcsil);
cetckzcr(vek);
cetckc(vek,hcsil);
return 0;
}