0% found this document useful (0 votes)
10 views9 pages

Program Coding - KLPK 8

The document presents programming examples for various algorithms including QuickSort, median calculation, matrix multiplication, and age validation. It is part of a mathematics algorithm course at Universitas Negeri Padang, presented by a group of students. Each program is implemented in C++ and demonstrates fundamental programming concepts.

Uploaded by

Wardah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

Program Coding - KLPK 8

The document presents programming examples for various algorithms including QuickSort, median calculation, matrix multiplication, and age validation. It is part of a mathematics algorithm course at Universitas Negeri Padang, presented by a group of students. Each program is implemented in C++ and demonstrates fundamental programming concepts.

Uploaded by

Wardah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

PROGRAM CODING

QUICKSORT, MEDIAN, PERKALIAN MATRIKS,


AMBANG BATAS (TRESHOLD)

Dipresentasikan dalam Mata Kuliah


Algoritma Matematika
yang diampu oleh: Maulani Meutia Rani S.Pd, M.Pd

Kelompok 8

Hamdan Alwi 21030007


Lifeni Triara 21030011
Nadilla Defira 21030101
Wardah Hasna Afifah 21030113
FAKULTAS MATEMATIKA DAN ILMU PENGETAHUAN ALAM
UNIVERSITAS NEGERI PADANG
2022

Program quick short

#include <iostream>

using namespace std;


void show(int arr[], int size)

{
for (int i = 0; i < size; i++)
cout << arr[i] << " ";
}

int partition(int arr[], int low, int high)

{
int pivot = arr[high];
int i = (low - 1);
for (int j = low; j < high; j++)
{
if (arr[j] <= pivot)
{
i++;
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
int temp = arr[i + 1];
arr[i + 1] = arr[high];
arr[high] = temp;
return (i + 1);
}

void quickSort(int arr[], int low, int high)


{
if (low < high)
{
int p = partition(arr, low, high);
quickSort(arr, low, p - 1);
quickSort(arr, p + 1, high);
}
}

int main()
{
int size;
cout << "\nmasukan banyaknya data : ";
cin >> size;
int arr[size];
cout << "\nmasukan nilai : ";
for (int i = 0; i < size; ++i)
{
cout << "\n";
cin >> arr[i];
}
quickSort(arr, 0, size);
cout << "Sorted array\n";
show(arr, size);

return 0;

}
Program median

#include <iostream>
#include <cstdlib>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;


int main(int argc, char** argv) {
int data[5];
int median,i;

for(i=0;i<5;i++){
cout<<"Masukan Data : "<<(i+1)<<"\n";
cin>>data[i];
}
i=i-1;
median=(i+1)/2;
cout<<endl<<data[median]<<endl;

return 0;
}

Program perkalian matriks

#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
int matriks1[10][10], matriks2[10][10];
int hasil[10][10];
int i, j, k, m, n, x, y, sum = 0;

cout << " =======PROGRAM PERKALIAN MATRIKS=======" << endl << endl;
q: cout << " Jumlah Baris Matriks A : "; cin >> m;
cout << " Jumlah Kolom Matriks A : "; cin >> n;
cout << " Jumlah Baris Matriks B : "; cin >> x;
cout << " Jumlah Kolom Matriks B : "; cin >> y;
cout << endl;
cout << " =======================================";
if (n != x){
cout << "\n\n Matriks Tidak Dapat Dikalikan. \n Silahkan Input Ulang\n\n";
goto q;
} else {
cout << "\n\n Input Elemen Matriks A" << endl;
for ( i = 0; i < m; i++){
for ( j = 0; j < n; j++){
cout << " Matriks A [" << i << "]["<< j <<"] : ";cin >> matriks1[i][j];
}
}
cout << endl;
cout << " =======================================";
cout << "\n\n Input Elemen Matriks B" << endl;
for ( i = 0; i < x; i++){
for ( j = 0; j < y; j++){
cout << " Matriks B [" << i <<"]["<< j <<"] : ";cin >> matriks2[i][j];
}
}

for (i = 0; i < m; i++){


for (j = 0; j < y; j++){
for (k = 0; k < x; k++){
sum = sum + matriks1[i][k] * matriks2[k][j];
}
hasil [i][j] = sum;
sum = 0;
}
}
cout << endl;
cout << " =======================================";
cout << "\n\n Hasil Perkalian Matriks" << endl << endl;
for (i = 0; i < m; i++){
for (j = 0; j < n; j++){
cout << " " << hasil[i][j] << "\t";
}
cout << endl;
}
}
return 0;
}
Program ambang batas

#include <iostream>

int main() {

int umur;

std::cout << "--------------------------------------" << std::endl;


std::cout << "\tProgram Validasi Umur" << std::endl;
std::cout << "--------------------------------------" << std::endl;

std::cout << "\nMasukkan Umur : ";


std::cin >> umur;

if(umur > 17) {

std::cout << "\nUmur lebih dari 17, kamu bisa menonton film ini." << std::endl;

} else {

std::cout << "\nKamu masih terlalu muda, tunggu " << (17 - umur) << " tahun lagi." <<
std::endl;
}

std::cout << std::endl;

return 0;
}

You might also like