ASSALAMUALAIKUM WR.WB
iini adalah diktat algoritma dan pemrograman pada bab 9 mari check this out :
NO.1 :
C++ :
#include <iostream>
#define maks 10
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int A[maks][maks], baris, kolom;
cout<<"input baris :"; cin>>baris;
cout<<"input kolom :"; cin>>kolom;
for(int i=0; i<baris; i++){
for(int j=0; j<kolom; j++){
cout<<"Masukan data ke ["<<i<<"] ["<<j<<"] : "; cin>>A[i][j];
}
}
cout<<"Isi Matriks A :\n";
for(int i=0; i<baris; i++){
for(int j=0; j<kolom; j++){
cout<<A[i][j]<<" ";
}
cout<<endl;
}
int m[baris],n;
cout<<"penghitungan vektor \n";
cout<<"berapa variabel : ";
cin>>m[kolom];
for(int z=0; z<kolom; z++){
cout<<"Masukan data ke ["<<z<<"] "" : "; cin>>m[z];
}
cout<<endl;
cout<<" vektor b : \n";
for(int z=0; z<kolom; z++){
cout<<m[z]<<"\n";
}
cout<<"perkalian matrik dan vektor \n";
for(int i=0; i<baris; i++){
for(int j=0; j<kolom; j++){
for(int z=0; z<kolom; z++){
n=A[i][j]*m[z];
cout<<n<<" ";
}
}
}
return 0;
}
NO.2
C++ :
#include"iostream"
using namespace std;
main(){ int i,j,n;
cout<<"masukkan ordo matriks : "; cin>>n;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(i==j) cout<<"1 ";
else cout<<"0 ";
}
cout<<endl;
}
}
NO.3
C++ :
#include"iostream"
using namespace std;
main(){ int i,j,m,n,o;
cout<<"Program transpose matriks C(m,n)\nMasukkan nilai m : ";
cin>>m; cout<<"masukkan nilai n : "; cin>>n;
int mat[m][n];
for(i=0;i<m;i++){
for(j=0;j<n;j++){
cout<<"nilai C("<<i+1<<","<<j+1<<")=";
cin>>mat[i][j];
}
cout<<endl;
}
system("cls");
cout<<"matriks diatas diilustrasikan seperti gambaran dibawah ini\n\n";
for(i=0;i<m;i++){
for(j=0;j<n;j++){
cout<<mat[i][j]<<" ";
}
cout<<endl;
}
o=m; m=n; n=o;
cout<<"\nTranspose matriksnya adalah seperti gambar dibawah ini\n\n";
for(j=0;j<m;j++){
for(i=0;i<n;i++){
cout<<mat[i][j]<<" ";
}
cout<<endl;
}
}
NO.4
C++ :
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
void Masukan(int *q, int brs, int klm) {
int i, j;
for(i = 0; i < brs; i++) {
for(j = 0; j < klm; j++) {
cout << " Elemen [" << (i + 1) << "][" << (j + 1) << "]? ";
scanf("%d", (q + i * klm + j));
}
}
}
void Tampilkan(int *q, int brs, int klm) {
int i, j;
for(i = 0; i < brs; i++) {
cout << endl;
for(j = 0; j < klm; j++) {
cout <<" ";
cout << *(q + i * klm + j) << "\t";
}
}
cout << endl;
}
void Kali(int *p, int *q, int *z, int bA, int kA, int bB, int kB) {
int i, j, k;
for(i = 0; i < bA; i++) {
for(j = 0; j < kB; j++) {
*(z + i * bB + j) = 0;
for(k = 0; k < kA; k++) {
*(z + i * bB + j) += *(p + i * kA + k) * (*(q + k * kB + j));
}
}
}
}
int main() {
cout<<"\t\t\tPROGRAM : PERKALIAN MATRIKS DENGAN SKALAR\n";
awal:
int *a, *b, *c, brsA, klmA, brsB, klmB;
cout<<"\n SYARAT...!!!\n";
cout<<" Jumlah Kolom A HARUS SAMA dengan Baris B\n\n";
cout << " Jumlah Baris Matriks A? ";
cin >> brsA;
cout << " Jumlah Kolom Matriks A? ";
cin >> klmA;
cout << " Jumlah Baris Matriks B? ";
cin >> brsB;
cout << " Jumlah Kolom Matriks B? ";
cin >> klmB;
if(klmA != brsB) {
cout << " Perkalian TIDAK Dapat Dilakukan." << endl;
cout << " Jumlah Kolom A TIDAK Sama Dengan Jumlah Baris B." << endl;
} else {
a = (int *) malloc(brsA * klmA * 4);
b = (int *) malloc(brsB * klmB * 4);
c = (int *) malloc(brsA * klmB * 4);
cout << "\n Kordinat Inputan [y][x]" ;
cout << "\n Contoh: ordo 2x2" ;
cout << "\n [1][1]\t[1][2]\t" ;
cout << "\n [2][1]\t[2][2]\t" ;
cout << "\n\n Input Matriks A:\n" ;
cout << " ----------------\n";
Masukan(a, brsA, klmA);
cout << "\n Input Matriks B:\n" ;
cout << " ----------------\n";
Masukan(b, brsB, klmB);
cout << "\n Matriks A:" << endl;
Tampilkan(a, brsA, klmA);
cout << "\n Matriks B:" << endl;
Tampilkan(b, brsB, klmB);
Kali(a, b, c, brsA, klmA, brsB, klmB);
cout << "\n Matriks A x B:" << endl;
Tampilkan(c, brsA, klmB);
}
cout<<"\n\n Apakah Anda Ingin Mengulang [Y/N] ? " ;
char m ;
cin>>m;
if (m == 'y' || m== 'Y')
goto awal;
else if (m == 'n' || m== 'N')
{
goto akhir;
}
akhir:
cout<<"\n\n\t\t\t \"TERMA KASIH\"";
return 0;
}
NO.5
C++ :
#include"iostream"
using namespace std;
main(){ int i,j; float det,temp;
float mat[2][2], c[2][2], ci[2][2], ch[2][2];
for(i=0;i<2;i++){
for(j=0;j<2;j++){
cout<<"nilai C("<<i+1<<","<<j+1<<")=";
cin>>mat[i][j];
c[i][j]=mat[i][j];
}
cout<<endl;
}
cout<<"matriks diatas diilustrasikan seperti gambaran dibawah ini\n\n";
for(i=0;i<2;i++){
for(j=0;j<2;j++){
cout<<mat[i][j]<<" ";
}
cout<<endl;
}
mat[0][1]=-mat[0][1]; mat[1][0]=-mat[1][0];
temp=mat[0][0]; mat[0][0]=mat[1][1]; mat[1][1]=temp;
cout<<"\nadjoin dari matriks diatas adalah\n";
for(i=0;i<2;i++){
for(j=0;j<2;j++){
cout<<mat[i][j]<<" ";
}
cout<<endl;
}
det=mat[0][0]*mat[1][1]-mat[1][0]*mat[0][1];
det=1/(float)det;
cout<<"\nSedangkan untuk inversnya adalah sebagai berikut\n";
for(i=0;i<2;i++){
for(j=0;j<2;j++){
ci[i][j]=det*mat[i][j];
cout<<ci[i][j]<<" ";
}
cout<<endl;
}
for(i=0;i<2;i++){
for(j=0;j<2;j++){
for(int k=0;k<2;k++){
temp=c[i][k]*ci[k][j];
ch[i][j]=ch[i][j]+temp;
}
}
}
cout<<"\nhasil perkalian matriks asal dengan\nmatriks yang telah di invers adalah\n";
for(i=0;i<2;i++){
for(j=0;j<2;j++){
cout<<ch[i][j]<<" ";
}
cout<<endl;
}
}
RAPTOR :
NO.2
NO.3
NO.5