- Mengalikan vektor 2 elemen matrix 2x3 dan vektpr 3 elemen
- Input
vektor [3]={9,8,1}
vek[2]={1,2}
- Output
85
26
vektor elemen 2 dengan matrix 2x3 dan vektor elemen 3
595
104
3. Membuat Flowcart atau Algoritma
Deklarasai :
matrix[2][3]={9,7,4,3,2,1} = integer
vektor [3]={5,4,3} = integer
vek[2]={7,4} = integer
hasil[2]=0= integer
Deskrpsi :
write('MATRIX ELEMEN 2X3 : \n')
for i ß
0 to 2 do then a++
for j ß 0 to 3 then j++
hasil[a] ß hasil[a]+(matrix[a][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(‘HASIL MATRIX 2X3 DAN VEKTOR 3 ELEMEN : \n’)
for a ß
0 to 2 then a++
write(hasil[a]) end
for
write(‘HASIL VEKTOR 2 ELEMEN DENGAN MATIRIX ELEMEN 2X3 DAN VEKTOR 3 ELEMEN : \n’)
for a ß 0 to 2 then a++
hasil[i]
ßhasil[a]*vek[a];
write(hasil[a]) end
for
4. Test Menggunakan Data
Input :
matrix [2] [3] : | 6 3 9 |
| 1 6 7|
vektor [3] : | 6 |
| 2 |
| 7 |
vek [2] | 6 |
| 5 |
Output :
Hasil kali matrix 2x3 dan vvektor 3 elemen : 123
81
81
Hasil akhir : 738
405
5. Implementasi c++
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void kali(int matrix[2][3],int vektor[3],int hasil[2]){
cout<<"MATRIX ELEMEN 2X3: \n";
for(int a=0;a<2;a++){
for(int b=0;b<3;b++)
hasil[a]=hasil[a]+(matrix[a][b]*vektor[b]);
}
}
void cetaktrix(int hasil[][3]){
for(int a=0;a<2;a++){
for(int b=0;b<3;b++)
cout<<hasil[a][b]<<" ";
cout<<endl;
}
}
void cetaktor(int vektor[]){
cout<<"VEKTOR ELEMEN 3: \n";
for(int a=0;a<3;a++){
cout<<vektor[a]<<endl;
}
}
void cetakbar(int vek[]){
cout<<"VEKTOR 2 ELEMEN : \n";
for(int a=0;a<2;a++){
cout<<vek[a]<<endl;
}
}
void cetak(int hasil[]){
cout<<"HASIL MATRIX 2X3 DAN VEKTOR 3 ELEMEN : \n";
for(int a=0;a<2;a++){
cout<<hasil[a]<<endl;
}
}
void cetaka(int vek[2],int hasil[]){
cout<<"HASIL VEKTOR 2 ELEMEN DENGAN MATIRIX ELEMEN 2X3 DAN VEKTOR 3 ELEMEN : \n";
for(int a=0;a<2;a++){
hasil[a]=hasil[a]*vek[a];
cout<<hasil[a]<<endl;
}
}
int main(int argc, char** argv) {
int matrix[2][3]={6,3,9,1,6,7}, vektor[3]={6,2,9},vek[2]={6,5},hasil[2]={0};
kali(matrix,vektor,hasil);
cetaktrix(matrix);
cetaktor(vektor);
cetak(hasil);
cetakbar(vek);
cetaka(vek,hasil);
return 0;
}
6. Eksekusi
Tidak ada komentar:
Posting Komentar