Skip to content

Instantly share code, notes, and snippets.

@codersidprogrammer
Last active June 16, 2026 05:10
Show Gist options
  • Select an option

  • Save codersidprogrammer/4ca46f0e6d70e90b6639ed3a4aa99252 to your computer and use it in GitHub Desktop.

Select an option

Save codersidprogrammer/4ca46f0e6d70e90b6639ed3a4aa99252 to your computer and use it in GitHub Desktop.
Tugas pemrograman BION
/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
/**
Deskripsi:
- 12, 22 , (23, 35, 64) => J covering this process
- [64, 34], 25, 12, 22
- 64, [34, 25], 12, 22
- 64, 34, 25, [12, 22]
**/
// sortMe dapat digunakan dengan mode "asc" atau "desc"
void sortMe(int arr[], int n, char sort[4]) {
int i, j, temp;
for (i = 0; i < n-1; i++) { // membaca panjang array secara keseluruhan
for (j = 0; j < n - i - 1; j++) { // covering sorting process at micro level
if (sort == "asc"){
if (arr[j] > arr[j+1]) {
temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
}
}else {
if (arr[j] < arr[j+1]) {
temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
}
}
}
}
}
int main() {
int arr[] = {64, 34, 25, 12, 22};
int n = sizeof(arr)/sizeof(arr[0]);
sortMe(arr, n, "desc");
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment