MEMBUAT PROGRAM SEDERHANA MENGGUNAKAN ARRAY
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{ int matriksa [100][100];
int matriksb [100][100];
int b [100][100];
int i,j,barisa,koloma,barisb,kolomb;
cout << "jumlah baris1= ";
cin >>barisa;
cout << "jumlah kolom1= ";
cin >>koloma;
cout<<"jumlah baris2= ";
cin >>barisb;
cout <<"jumlah kolom2= ";
cin >>kolomb;
cout << "\n";
if (koloma != barisb)
cout << "Ukuran tidak valide";
else {
for (i=0; i < barisa; i++) {
for (j =0; j < koloma; j++) {
cout<<"isi matriks 1= [" << (i+1) << "," << (j+1) << "] : ";
cin>>matriksa [i][j];
}
}
for (i=0; i < barisb; i++) {
for (j=0; j < kolomb; j++) {
cout<<"isi matriks 2= [" << (i+1) << "," << (j+1) << "] : ";
cin>>matriksb [i][j];
}
}
cout << "hasil penjumlahan matriks 1 dan 2 = " << "\n" ;
for (i= 0; i< koloma; i++){
for (j=0 ; j< barisa;j++) {
b[i][j] = matriksa [i][j]+ matriksb [i][j];
cout << "matriks ["<< i+1 <<" ] ["<< j+1 <<" ] adalah " << b[i][j] <<"\n";
}
}
cout << "\n";
}
getch();
return 0;
}
Tidak ada komentar:
Posting Komentar