Yang pertama
Algoritma Program Penjumlahan Matriks 3x3, 2x1, 3x2
Matrik 3x3
#include <iostream.h>
#include <conio.h>
#define Nmaks 10
typedef int matrik[Nmaks][Nmaks];
void main()
{
int n,i,j;
matrik A,B,C;
cout<<"Program Penjumlahan Matrik 3x3"<<endl;
cout<<"=============================="<<endl;
cout<<endl;
n=3;
cout<<"Masukkan Entry Matrik A"<<endl<<endl;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
cout<<"A"<<"["<<i<<"]"<<"["<<j<<"]"<<" = ";
cin>>A[i][j];
}
}
cout<<endl;
cout<<"Masukkan Entry Matrik B"<<endl<<endl;
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
cout<<"B"<<"["<<i<<"]"<<"["<<j<<"]"<<" = ";
cin>>B[i][j];
}
}
//penjumlahan matrik C=A+B
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
C[i][j]=A[i][j]+B[i][j];
}
}
clrscr();
cout<<"Penjumlahan Matrik A dan B"<<endl;
//output matrik A
gotoxy(1,6);
cout<<"A = ";
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
gotoxy(2+4*j,2+2*i);
cout<<A[i][j];
}
}
//output matrik B
gotoxy(1,14);
cout<<"B = ";
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
gotoxy(2+4*j,5+2*i+5);
cout<<B[i][j];
}
}
//output matrik C = A + B
gotoxy(1,22);
cout<<"C = ";
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
gotoxy(2+4*j,8+2*i+10);
cout<<A[i][j];
}
}
gotoxy(18,22);
cout<<" + ";
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
gotoxy(20+4*j,8+2*i+10);
cout<<B[i][j];
}
}
//output hasil
gotoxy(38,22);
cout<<"=";
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
gotoxy(40+4*j,8+2*i+10);
cout<<C[i][j];
}
}
getch();
}
Matrik 2x1
#include <iostream.h>
#include <conio.h>
#define Nmaks 10
typedef int matrik[Nmaks][Nmaks];
void main()
{
int n,i,j,v;
matrik A,B,C;
cout<<"Program Perkalian Matrik 2x1"<<endl;
cout<<"=============================="<<endl;
cout<<endl;
n=2;
v=1;
cout<<"Masukkan Entry Matrik A"<<endl<<endl;
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
cout<<"A"<<"["<<i<<"]"<<"["<<j<<"]"<<" = ";
cin>>A[i][j];
}
}
cout<<endl;
cout<<"Masukkan Entry Matrik B"<<endl<<endl;
for (i=1;i<=n;i++)
{
for (j=1;j<=v;j++)
{
cout<<"B"<<"["<<i<<"]"<<"["<<j<<"]"<<" = ";
cin>>B[i][j];
}
}
//penjumlahan matrik C=A+B
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
C[i][j]=A[i][j]*B[i][j];
}
}
clrscr();
cout<<"Perkalian Matrik A dan B"<<endl;
//output matrik A
gotoxy(1,6);
cout<<"A = ";
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
gotoxy(2+4*j,2+2*i);
cout<<A[i][j];
}
}
//output matrik B
gotoxy(1,14);
cout<<"B = ";
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
gotoxy(2+4*j,5+2*i+5);
cout<<B[i][j];
}
}
//output matrik C = A * B
gotoxy(1,22);
cout<<"C = ";
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
gotoxy(2+4*j,8+2*i+10);
cout<<A[i][j];
}
}
gotoxy(18,22);
cout<<" * ";
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
gotoxy(20+4*j,8+2*i+10);
cout<<B[i][j];
}
}
//output hasil
gotoxy(38,22);
cout<<"=";
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
gotoxy(40+4*j,8+2*i+10);
cout<<C[i][j];
}
}
getch();
}
Matrik 3x2
#include <iostream.h>
#include <conio.h>
#define Nmaks 10
typedef int matrik[Nmaks][Nmaks];
void main()
{
int n,i,j,v;
matrik A,B,C;
cout<<"Program Perkalian Matrik 2x1"<<endl;
cout<<"=============================="<<endl;
cout<<endl;
n=3;
v=2;
cout<<"Masukkan Entry Matrik A"<<endl<<endl;
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
cout<<"A"<<"["<<i<<"]"<<"["<<j<<"]"<<" = ";
cin>>A[i][j];
}
}
cout<<endl;
cout<<"Masukkan Entry Matrik B"<<endl<<endl;
for (i=1;i<=n;i++)
{
for (j=1;j<=v;j++)
{
cout<<"B"<<"["<<i<<"]"<<"["<<j<<"]"<<" = ";
cin>>B[i][j];
}
}
//penjumlahan matrik C=A+B
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
C[i][j]=A[i][j]*B[i][j];
}
}
clrscr();
cout<<"Perkalian Matrik A dan B"<<endl;
//output matrik A
gotoxy(1,6);
cout<<"A = ";
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
gotoxy(2+4*j,2+2*i);
cout<<A[i][j];
}
}
//output matrik B
gotoxy(1,14);
cout<<"B = ";
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
gotoxy(2+4*j,5+2*i+5);
cout<<B[i][j];
}
}
//output matrik C = A * B
gotoxy(1,22);
cout<<"C = ";
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
gotoxy(2+4*j,8+2*i+10);
cout<<A[i][j];
}
}
gotoxy(18,22);
cout<<" * ";
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
gotoxy(20+4*j,8+2*i+10);
cout<<B[i][j];
}
}
//output hasil
gotoxy(38,22);
cout<<"=";
for(i=1;i<=n;i++)
{
for(j=1;j<=v;j++)
{
gotoxy(40+4*j,8+2*i+10);
cout<<C[i][j];
}
}
getch();
}
Hasilnya inputkan angka sendiri -sendiri ya....!! hahaha