0% found this document useful (0 votes)
52 views2 pages

Tugas Penjumlahan Matriks Alpr0 - Putri Nurrifkadillah - k1b020002

This C++ program allows a user to input two matrices, store them in arrays, check that they can be added, and then output the sum of the matrices. It uses functions to get input, display the individual matrices, check they can be added, and perform the addition. The main function controls the overall flow by getting a menu selection from the user and calling the appropriate functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views2 pages

Tugas Penjumlahan Matriks Alpr0 - Putri Nurrifkadillah - k1b020002

This C++ program allows a user to input two matrices, store them in arrays, check that they can be added, and then output the sum of the matrices. It uses functions to get input, display the individual matrices, check they can be added, and perform the addition. The main function controls the overall flow by getting a menu selection from the user and calling the appropriate functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

using namespace std;


int hasil[2][10][10];
int panjang[2][2];
int row = 0;
int col = 0;

void isiData (int jumlahMatriks) {


cout <<"Ordo Matrix"<<jumlahMatriks+1<<endl;
scanf("%d",&row);
cout<<"x"<<endl;
scanf ("%d", &col);
int matriks [row][col];

panjang[jumlahMatriks][0]= row;
panjang[jumlahMatriks][1]= col;

cout<<endl;

for(int x=0; x<row; x++){


for(int y=0;y<col;y++){
cout<<"Index("<<x+1<<","<<y+1<<"):";
scanf("%d", &matriks[x][y]);
hasil[jumlahMatriks][x][y]=matriks[x][y];
}
}
cout << endl;
}
void tampilData (int jumlahMatriks) {
for(int x=0; x<panjang[jumlahMatriks][0];x++){
cout<<"";
for(int y=0;y<panjang[jumlahMatriks][1];y++){
cout<<hasil[jumlahMatriks][x][y]<<" ";
}
cout<<""<<endl;
}
cout<<endl;
}
void penjumlahan(){
bool a= panjang[0][0]== panjang[1][0];
bool b= panjang[0][1]== panjang[1][1];

if (a&&b) {
for(int x=0;x<panjang[0][0];x++){
cout<<"";
for(int y=0;y<panjang[0][1];y++){
cout<<hasil[0][x][y]+hasil[1][x][y]<<" ";
}
cout<<""<<endl;
}
}
}
int main()
{
cout<<"Nama : Putri Nurrifkadillah"<<endl;
cout<<"NIM : K1B020002"<<endl;
cout<<"======================================"<<endl;
cout<<"Penjumlahan Matriks "<<endl;
cout<<"======================================"<<endl;
int input = 2;
do{
cout<<"1. Isi data"<<endl;
cout<<"2. Penjumlahan"<<endl;
cout<<"Pilihan:";

scanf("%d", &input);
if(input==1){
for(int i=0;i<2;i++){
isiData(i);
}
}else if (input==2){
for(int i=0;i<2;i++){
tampilData(i);
if(i==0){
cout<<"+"<<endl;
}else{
cout<<"="<<endl;
}
}
penjumlahan();
}else{
cout<<"Pilihan tidak tersedia"<<endl<<endl;
}

}while(input !=2);
return 0;
}

You might also like