Assalamuallaikum wr wb
saya masih posting tentang pemrograman C++ yang berhubungan dengan adanya permintaan dari teman.
Penjumlahan duan buah matriks
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
int A[2][2],B[2][2],C[2][2];
void inputmatriksA()
{cout<<"Matriks A"<<endl;
for (int i=0;i<2;i++)
for (int j=0;j<2;j++)
{cout<<"Elemen A ["<<(i+1)<<","<<(j+i)<<"]:";
cin>>A[i][j];}}
void inputmatriksB()
{cout<<"Matriks B"<<endl;
for (int i=0;i<2;i++)
for (int j=0;j<2;j++)
{cout<<"Elemen B ["<<(i+1)<<","<<(j+i)<<"]:";
cin>>B[i][j];}}
void tampilA()
{cout<<"Matriks A"<<endl;
for (int i=0;i<2;i++)
{for (int j=0;j<2;j++)
cout<<setw(2)<<A[i][j]<<" ";
cout<<endl;}}
void tampilB()
{cout<<"Matriks B"<<endl;
for (int i=0;i<2;i++)
{for (int j=0;j<2;j++)
cout<<setw(2)<<B[i][j]<<" ";
cout<<endl;}}
void tampilC()
{cout<<"Jumlah Matriks A & B"<<endl;
for (int i=0;i<2;i++)
{for (int j=0;j<2;j++)
cout<<setw(2)<<C[i][j]<<" ";
cout<<endl;}}
void Jumlah()
{for (int i=0;i<2;i++)
{for (int j=0;j<2;j++)
C[i][j]=A[i][j]+B[i][j];
cout<<endl;}}
void main()
{clrscr();
cout<<"\n Penjumlahan 2 Buah Matriks "<<endl;
cout<<"======================================="<<endl;
inputmatriksA();
cout<<"======================================="<<endl;
inputmatriksB();
cout<<"======================================="<<endl;
cout<<endl;
clrscr();
cout<<"\n\tTampilan Matriks A "<<endl;
cout<<"======================================================"<<endl;
tampilA();
cout<<"\n\tTampilan Matriks B "<<endl;
cout<<"======================================================"<<endl;
tampilB();
Jumlah();
cout<<"\nMaka Penjumlahan dari matriks diatas adalah "<<endl;
cout<<"======================================================"<<endl;
tampilC();
getch();
}
0 komentar:
Posting Komentar