0% found this document useful (0 votes)
23 views

Listing Program C++ Penjumlahan Dan Perkalian 2 Buah Matrix

This C++ program allows users to input two matrices (A and B) and calculates their product (C). It first prompts the user to enter the number of rows and columns for matrices A and B. It then inputs the values for matrices A and B. The program contains an algorithm to calculate the product of the matrices based on the number of columns in A. It outputs the original matrices A and B as well as the product matrix C.

Uploaded by

efulah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Listing Program C++ Penjumlahan Dan Perkalian 2 Buah Matrix

This C++ program allows users to input two matrices (A and B) and calculates their product (C). It first prompts the user to enter the number of rows and columns for matrices A and B. It then inputs the values for matrices A and B. The program contains an algorithm to calculate the product of the matrices based on the number of columns in A. It outputs the original matrices A and B as well as the product matrix C.

Uploaded by

efulah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

LISTING PROGRAM C++

penjumlahan dan perkalian 2 buah Matrix


Saeful Munawar :18101184
Indra Permana :18101161
Arief dibyo Widjaya :18101113
Rika raraswati :1810116
Edo Firnando :18101160
Ayu cyntia meilina :1810116

#include <iostream.h>
 #include <conio.h>
 #include <stdio.h>

 #define ValueMax 25

 typedef float matriks[ValueMax][ValueMax];

 void main()
 {

 int colA,colB,rowA,rowB,i,j;
 matriks A,B,C;
 int answer;

 do
 {
  clrscr();
  cout<<"\aAnda Memilih Menu Perkalian Matriks\n\n\n";
  cout<<"MATRIKS A : "<<endl<<endl;
  cout<<"Masukkan Jumlah Baris Matriks A : ";
  cin>>rowA;
  cout<<"Masukkan Jumlah Kolom Matriks A : ";
  cin>>colA;
  cout<<endl<<endl;
  cout<<"MATRIKS B : "<<endl<<endl;
  cout<<"Masukkan Jumlah Baris Matriks B : ";
  cin>>rowB;
  cout<<"Masukkan Jumlah Kolom Matriks B : ";
  cin>>colB;
 }
 while (colA!=rowB);
 clrscr();
 cout<<"Masukkan Nilai Matriks A : "<<endl;
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colA;j++)
 {
   cout<<"A["<<i<<","<<j<<"] = ";
   cin>>A[i][j];
 }
 }

 cout<<endl<<endl;
 cout<<"Masukkan Nilai Matriks B : "<<endl;
 for(i=1;i<=rowB;i++)
 {
  for(j=1;j<=colB;j++)
 {
   cout<<"B["<<i<<","<<j<<"] = ";
   cin>>B[i][j];
 }
 }

 clrscr();
 cout<<endl;
 //Proses Perkalian Matriks
 if(colA == 1)
 {
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colB;j++)
 {
    C[i][j] = (A[i][1] * B[1][j]);
 }
 }
 }

 if(colA == 2)
 {
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colB;j++)
 {
    C[i][j] = (A[i][1] * B[1][j] + A[i][2] * B[2][j]);
 }
 }
 }
 if(colA == 3)
 {
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colB;j++)
 {
    C[i][j] = (A[i][1] * B[1][j] + A[i][2] * B[2][j] + A[i][3] * B[3][j]);
 }
 }
 }

 if(colA == 4)
 {
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colB;j++)
 {
    C[i][j] = (A[i][1]*B[1][j] + A[i][2]*B[2][j] + A[i][3]*B[3][j] + A[i][4]*B[4][j]);
 }
 }
 }

 if(colA == 5)
 {
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colB;j++)
 {
    C[i][j] = (A[i][1]*B[1][j] + A[i][2]*B[2][j] + A[i][3]*B[3][j] + A[i][4]*B[4][j] + A[i][5]*B[5]
[j]);
 }
 }
 }

 clrscr();
 //Output Matriks A
 gotoxy(1,5);
 cout<<"A = ";
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colA;j++)
 {
   gotoxy(2+4*j,2+2*i);
   cout<<A[i][j];
 }
 }

 //Output Matriks B
 gotoxy(1,17);
 cout<<"B = ";
 for(i=1;i<=rowB;i++)
 {
  for(j=1;j<=colB;j++)
 {
   gotoxy(2+4*j,14+2*i);
   cout<<B[i][j];
 }
 }

 //Output Matriks C
 gotoxy(1,30);
 cout<<"C = ";
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colA;j++)
 {
   gotoxy(3+4*j,27+2*i);
   cout<<A[i][j];
 }
 }

 gotoxy(25,30);
 cout<<" X ";
 for(i=1;i<=rowB;i++)
 {
  for(j=1;j<=colB;j++)
 {
   gotoxy(26+4*j,27+2*i);
   cout<<B[i][j];
 }
 }

 gotoxy(43,30);
 cout<<" = ";
 for(i=1;i<=rowA;i++)
 {
  for(j=1;j<=colB;j++)
 {
   gotoxy(45+4*j,27+2*i);
   cout<<C[i][j];
 }
 }

 getch();
}

You might also like