PROGRAM MENGUNAAN FUNGCTION MATRIK ORDO BEBAS
#include <iostream.h>
#include <conio.h>
void main()
{
//Variabel-Variabel
int i, j, k, el, aa, ab, bb, jumlah, pilihan, matriks1[10][10], matriks2[10][10], hasil[10][10];
clrscr;
cout <<" Program Perhitung matrik A dan matrik B\n";
cout <<"masukkan jumlah baris matriks A : "; cin >>el;
cout <<"masukkan jumlah kolom matriks A : "; cin >>aa;
//Input matriks A
cout <<"------------------------------------------\n";
cout << "Masukkan elemen matrik A : ";
for(i = 0; i < el; i++)
{
for(j = 0; j < aa; j++)
{
gotoxy(29+j*3,5+i); cin >> matriks1[i][j];
}
}
cout <<"----------------------------------------------\n";
cout <<"1. Perkalian\n";
cout <<"2. Penjumlahan\n";
cout <<"3. Pengurangan\n";
cout <<"4. Tranpose\n";
cout <<"----------------------------------------------\n";
cout <<"Tentukan pilihan anda(1/2/3/4) : "; cin >> pilihan;
while (pilihan<1 || pilihan>4)
{
cout <<"Pilihan Yang Anda masukkan TIDAK TERSEDIA!!!\n";
cout <<"Tentukan pilihan anda(1/2/3/4) : "; cin >> pilihan;
}
if (pilihan==1)
{
clrscr;
ab=aa;
bb=el;
cout <<"Program Perkalian Matriks A ("<<el<<"X"<<aa<<") dan Matriks B ("<<ab<<"X"<<bb<<")\n";
cout <<"-------------------------------------------------\n";
//Input matriks B
cout <<"\n";
cout << "Masukkan elemen matrik B : ";
for(i = 0; i < ab; i++)
{
for(j = 0; j < bb; j++)
{
gotoxy(29+j*3,17+i+el-2);cin >> matriks2[i][j];
}
}
//Menghitung Perkalian Matriks
for(i = 0; i < el; i++)
{
for(j = 0; j < aa; j++)
{
for (k=0; k<el; k++)
{
jumlah = jumlah + matriks1[i][k] * matriks2[k][j] ;
}
hasil[i][j]=jumlah;
jumlah=0;
}
}
}
else if (pilihan==2)
{
clrscr;
ab=el;
bb=aa;
cout <<"Program Penjumlahan Matriks A ("<<el<<"X"<<aa<<") dan Matriks B ("<<ab<<"X"<<bb<<")\n";
cout <<"-------------------------------------------------\n";
//Input matriks B
cout <<"\n";
cout << "Masukkan elemen matrik B : ";
for(i = 0; i < ab; i++)
{
for(j = 0; j < bb; j++)
{
gotoxy(29+j*3,17+i+el-2);cin >> matriks2[i][j];
}
}
//Menghitung penjumlahan matriks
for(i = 0; i < el; i++)
{
for(j = 0; j < aa; j++)
{
hasil[i][j] = matriks1[i][j] + matriks2[i][j];
}
}
}
else if (pilihan==3)
{
clrscr;
ab=el;
bb=aa;
cout <<"Program Pengurangan Matriks A ("<<el<<"X"<<aa<<") dan Matriks B ("<<ab<<"X"<<bb<<")\n";
cout <<"-------------------------------------------------\n";
//Input matriks B
cout <<"\n";
cout << "Masukkan elemen matrik B : ";
for(i = 0; i < ab; i++)
{
for(j = 0; j < bb; j++)
{
gotoxy(29+j*3,17+i+el-2);cin >> matriks2[i][j];
}
}
//Menghitung pengurngan matriks
for(i = 0; i < el; i++)
{
for(j = 0; j < aa; j++)
{
hasil[i][j] = matriks1[i][j] - matriks2[i][j];
}
}
}
else
{
clrscr;
cout <<"Program Transpose Matriks A\n";
cout <<"-----------------------------------------\n";
//Menghitung penjumlahan matriks
for(i = 0; i < el; i++)
{
for(j = 0; j < aa; j++)
{
hasil[i][j] = matriks1[j][i];
}
}
}
//Output mulai dari sini
if (pilihan==1)
{
cout << "\nHasil perkalian matrik A dan matrik B : \n";
}
else if (pilihan==2)
{
cout << "\nHasil penjumlahan matrik A dan matrik B : \n";
}
else if (pilihan==3)
{
cout << "\nHasil pengurangan matrik A dan matrik B : \n";
}
else
{
cout << "\nHasil Transpose matrik A\n";
}
//Menampilkan matriks A
for(i = 0; i < el; i++)
{
for(j = 0; j < aa; j++)
{
gotoxy(5+j*4,21+i+el+aa-4);cout <<matriks1[i][j];
}
}
if (pilihan==1)
{
cout <<" (x)";
}
else if (pilihan==2)
{
cout <<" (+)";
}
else if (pilihan==3)
{
cout <<" (-)";
}
else
{
cout <<" TR";
}
if (pilihan!=4)
{
//Menampilkan matriks B
ab=aa; bb=el;
for(i = 0; i < ab; i++)
{
for(j = 0; j < bb; j++)
{
gotoxy(17+(aa-2)*4+j*4,21+i+el+ab-4); cout <<matriks2[i][j];
}
}
}
cout <<" (=)";
//Menampilkan Hasil Perkalian
for(i = 0; i < el; i++)
{
for(j = 0; j < aa; j++)
{
gotoxy(28+(aa+el-4)*4+j*4,21+i+el+aa-4);
cout << hasil[i][j];
}
}
getch();
}
outputnya
Tidak ada komentar:
Posting Komentar