program penjumlahan,pengurangan,dan perkalian pada matriks
1.penjumlahan
#include <stdio.h>
#include <conio.h>
void main()
{
int j,i,a[2][2],b[2][2],c[2][2];
a[0][0]=1;
a[0][1]=2;
a[1][0]=5;
a[1][1]=6;
b[0][0]=1;
b[0][1]=2;
b[1][0]=5;
b[1][1]=6;
printf("Matrik a \n");
for (i=0; i<2; i++){
for(j=0;j<2;j++){
printf(" %d",a[i][j]);
}
printf("\n");
}
printf("Matrik b \n");
for (i=0; i<2; i++){
for(j=0;j<2;j++){
printf(" %d",b[i][j]);
}
printf("\n");
}
printf("Hasil a+b \n");
for (i=0; i<2; i++){
for(j=0;j<2;j++){
c[i][j]=a[i][j]+b[i][j];
printf(" %d",c[i][j]);
}
printf("\n");
}
getch();
}
__________________________________________________________________________________
2.pengurangan
#include
#include
#include
int i, j, baris, kolom, m1[10]
[10], m2[10]
[10], hasil[10]
[10];
void main()
{
clrscr();
cout << "Operasi Pengurangan Matrixn";
do
{
cout << "Jumlah Baris = "; cin>>baris;
cout << "Jumlah Kolom = "; cin>>kolom;
}
while((baris>10)||(kolom>10));
/* do
while(kolom>10);*/
cout << "nMatrix A" << endl;
for(i=0;i
for(j=0;j
{
cout <<"data [" << i << "," << j << "] = ";
cin>>m1[i]
[j];
}
cout << "nMatrix B" << endl;
for(i=0;i
for(j=0;j
{
cout <<"data [" << i << "," << j << "] = ";
cin>>m2[i]
[j];
}
for(i=0; i
for(j=0; j
hasil[i]
[j] = m1[i]
[j] - m2[i]
[j];
cout << "nHasilnya..." << endl;
cout << "Matrix A - Matrix B = Matrix C";
for(i=0; i< baris; i++)
{
cout<<'n';
for(j=0; j
cout << setw(4) << m1[i]
[j];
cout << " ";
for(j=0; j
cout << setw(4) << m2[i]
[j];
cout << " ";
for(j=0; j
cout << setw(4) << hasil[i]
[j];
cout << endl;
}
getch();
}
______________________________________________________________________________________
3.perkalian
#include <iostream.h>
| | int A[3][3],B[3][3],C[3][3],i,j,k; |
| cout<<"Silahkan input matrik A : \n"; |
| cout<<"------------------------- \n"; |
| cout<<"Elemen ke "<<(i+1)<<","<<(j+1)<<" : "; |
| cout<<"\nMatrik A : \n";; |
| cout<<"Silahkan input matrik B : \n"; |
| cout<<"------------------------- \n"; |
| cout<<"Elemen ke "<<(i+1)<<","<<(j+1)<<" : "; |
| C[i][j]+= A[i][k]*B[k][j]; |
| cout<<"\nMatrik C, Hasil : \n"; |