1. Matrik Perkalian (silahkan dipelajari sendiri gan, haha)
/*Matriks*/
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
main()
{
int i, j, k, barisa, koloma, barisb, kolomb;
int matriks1[10][10], matriks2[10][10], hasil[10][10];
char ulang;
clrscr();
cout<<"PERKALIAN MATRIKS by IMAM THOIB"<<endl;
cout<<"-------------------------------"<<endl<<endl;
input:
cout<<"MATRIKS A"<<endl;
cout<<"---------"<<endl<<endl;
cout<<"Masukkan jumlah baris : ";
cin>>barisa;
cout<<"Masukkan jumlah kolom : ";
cin>>koloma;
cout<<endl<<endl;
cout<<"MATRIKS B"<<endl;
cout<<"---------"<<endl<<endl;
cout<<"Masukkan jumlah baris : ";
cin>>barisb;
cout<<"Masukkan jumlah kolom : ";
cin>>kolomb;
cout<<endl<<endl;
if(koloma==barisb)
{
goto operasi;
}
else
{
cout<<"Tidak dapat diidentifikasi"<<endl;
cout<<"Jumlah kolom Matriks A harus sama dengan jumlah baris Matriks B!"<<endl<<endl;
goto ulang;
}
operasi:
cout<<"Masukkan Elemen Matriks!"<<endl;
cout<<"------------------------"<<endl<<endl;
//Matriks A
cout<<"Masukkan elemen Matriks A!"<<endl;
for(i=0;i<barisa;i++)
{
for(j=0;j<koloma;j++)
{
cout<<"Baris ke - "<<i+1<<" kolom ke - "<<j+1<<" : ";
cin>>matriks1[i][j];
}
}
cout<<endl;
cout<<"Matriks A"<<endl;
cout<<"---------"<<endl;
for(i=0;i<barisa;i++)
{
cout<<"|";
for(j=0;j<koloma;j++)
{
cout<<setiosflags(ios::right)<<setw(4)<<matriks1[i][j];
cout<<" ";
}
cout<<"|"<<endl;
}
cout<<endl<<endl;
//Matriks B
cout<<"Masukkan elemen Matriks B!"<<endl;
for(i=0;i<barisb;i++)
{
for(j=0;j<kolomb;j++)
{
cout<<"Baris ke - "<<i+1<<" kolom ke - "<<j+1<<" : ";
cin>>matriks2[i][j];
}
}
cout<<endl;
cout<<"Matriks B"<<endl;
cout<<"---------"<<endl;
for(i=0;i<barisb;i++)
{
cout<<"|";
for(j=0;j<kolomb;j++)
{
cout<<setiosflags(ios::right)<<setw(4)<<matriks2[i][j];
cout<<" ";
}
cout<<"|"<<endl;
}
cout<<endl;
//Operasi
for(i=0;i<barisa;i++)
{
for(j=0;j<kolomb;j++)
{
hasil[i][j]=0;
for(k=0;k<koloma;k++)
{
hasil[i][j] += matriks1[i][j]*matriks2[i][j];
}
}
}
cout<<"Hasil dari Matriks A x Matriks B:"<<endl;
cout<<"---------------------------------"<<endl;
//Hasil
for(i=0;i<barisa;i++)
{
cout<<"|";
for(j=0;j<kolomb;j++)
{
cout<<setiosflags(ios::right)<<setw(4)<<hasil[i][j];
cout<<" ";
}
cout<<"|"<<endl;
}
cout<<endl;
cout<<"Selamat! Anda berhasil melakukan operasi perkalian matriks."<<endl;
ulang:
cout<<"Coba lagi? (y/n) : ";
cin>>ulang;
cout<<endl;
if(ulang=='y'||ulang=='Y')
{
goto input;
}
else if(ulang=='n'||ulang=='N')
{
goto tengyu;
}
else
{
cout<<"Pilihan Anda Salah!"<<endl;
goto ulang;
}
tengyu:
cout<<"Terima Kasih"<<endl;
getch();
}
2. Matrik Penjumlahan
/*Matriks*/
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
main()
{
int i, j, barisa, koloma, barisb, kolomb;
int matriks1[10][10], matriks2[10][10], hasil[10][10];
char ulang;
clrscr();
cout<<"PENJUMLAHAN MATRIKS by IMAM THOIB"<<endl;
cout<<"---------------------------------"<<endl<<endl;
input:
cout<<"MATRIKS A"<<endl;
cout<<"---------"<<endl<<endl;
cout<<"Masukkan jumlah baris : ";
cin>>barisa;
cout<<"Masukkan jumlah kolom : ";
cin>>koloma;
cout<<endl<<endl;
cout<<"MATRIKS B"<<endl;
cout<<"---------"<<endl<<endl;
cout<<"Masukkan jumlah baris : ";
cin>>barisb;
cout<<"Masukkan jumlah kolom : ";
cin>>kolomb;
cout<<endl<<endl;
if(barisa==barisb&&koloma==kolomb)
{
goto operasi;
}
else
{
cout<<"Tidak dapat diidentifikasi"<<endl;
cout<<"Jumlah baris & kolom Matriks A harus sama dengan jumlah baris & kolom Matriks B!"<<endl<<endl;
goto ulang;
}
operasi:
cout<<"Masukkan Elemen Matriks!"<<endl;
cout<<"------------------------"<<endl<<endl;
//Matriks A
cout<<"Masukkan elemen Matriks A!"<<endl;
for(i=0;i<barisa;i++)
{
for(j=0;j<koloma;j++)
{
cout<<"Baris ke - "<<i+1<<" kolom ke - "<<j+1<<" : ";
cin>>matriks1[i][j];
}
}
cout<<endl;
cout<<"Matriks A"<<endl;
cout<<"---------"<<endl;
for(i=0;i<barisa;i++)
{
cout<<"|";
for(j=0;j<koloma;j++)
{
cout<<setiosflags(ios::right)<<setw(4)<<matriks1[i][j];
cout<<" ";
}
cout<<"|"<<endl;
}
cout<<endl<<endl;
//Matriks B
cout<<"Masukkan elemen Matriks B!"<<endl;
for(i=0;i<barisb;i++)
{
for(j=0;j<kolomb;j++)
{
cout<<"Baris ke - "<<i+1<<" kolom ke - "<<j+1<<" : ";
cin>>matriks2[i][j];
}
}
cout<<endl;
cout<<"Matriks B"<<endl;
cout<<"---------"<<endl;
for(i=0;i<barisb;i++)
{
cout<<"|";
for(j=0;j<kolomb;j++)
{
cout<<setiosflags(ios::right)<<setw(4)<<matriks2[i][j];
cout<<" ";
}
cout<<"|"<<endl;
}
cout<<endl;
//Operasi
for(i=0;i<barisa;i++)
{
for(j=0;j<kolomb;j++)
{
hasil[i][j] = matriks1[i][j]+matriks2[i][j];
}
}
cout<<"Hasil dari Matriks A + Matriks B:"<<endl;
cout<<"---------------------------------"<<endl;
//Hasil
for(i=0;i<barisa;i++)
{
cout<<"|";
for(j=0;j<kolomb;j++)
{
cout<<setiosflags(ios::right)<<setw(4)<<hasil[i][j];
cout<<" ";
}
cout<<"|"<<endl;
}
cout<<endl;
cout<<"Selamat! Anda berhasil melakukan operasi penjumlahan matriks."<<endl;
ulang:
cout<<"Coba lagi? (y/n) : ";
cin>>ulang;
cout<<endl;
if(ulang=='y'||ulang=='Y')
{
goto input;
}
else if(ulang=='n'||ulang=='N')
{
goto tengyu;
}
else
{
cout<<"Pilihan Anda Salah!"<<endl;
goto ulang;
}
tengyu:
cout<<"Terima Kasih"<<endl;
getch();
}
gitu saja ya postingnya, bye bye.....
Tidak ada komentar:
Posting Komentar
Tinggalkan komentar Anda setelah Anda membaca tulisan saya. Anda bebas menggandakan artikel dari blog ini asal tuliskan tautan balik blog ini.Terima kasih atas kunjungan teman-teman.