This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| #include <ctype.h> | |
| #include <stdlib.h> | |
| #define MAX_DATA 1000 | |
| // ======================= | |
| // STRUCT DATA | |
| // ======================= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int main() { | |
| // Data nilai siswa | |
| int nilai[5] = {80, 85, 70, 75, 90}; | |
| int jumlahSiswa = 5; | |
| int min = nilai[0]; | |
| int max = nilai[0]; | |
| int total = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Contoh: Pencarian Biner menggunakan rekursi | |
| #include <iostream> | |
| using namespace std; | |
| int binarySearch(int array[], int low, int high, int x) { | |
| if (high >= low) { | |
| int mid = low + (high - low) / 2; | |
| if (array[mid] | |
| return mid; | |
| if (array[mid] > x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Contoh: Deret Fibonacci menggunakan rekursi | |
| #include <iostream> | |
| using namespace std; | |
| int fibonacci(int n) { | |
| if (n <= 1) | |
| return n; | |
| else | |
| return fibonacci(n - 1) + fibonacci(n - 2); | |
| } | |
| int main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Contoh: Faktorial menggunakan iterasi | |
| #include <iostream> | |
| using namespace std; | |
| int faktorialIteratif(int n) { | |
| int hasil = 1; | |
| for (int i = 1; i <= n; ++i) { | |
| hasil *= i; | |
| } | |
| return hasil; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Contoh: Faktorial menggunakan rekursi | |
| #include <iostream> | |
| using namespace std; | |
| int faktorial(int n) { | |
| if (n <= 1) // Kasus dasar | |
| return 1; | |
| else | |
| return n * faktorial(n - 1); // Kasus rekursif | |
| } | |
| int main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Contoh: Fungsi rekursif untuk menampilkan "Hello World" se | |
| #include <iostream> | |
| using namespace std; | |
| void cetakHelloWorld(int n) { | |
| if (n <= 0) | |
| return; | |
| cout << "Hello World" << endl; | |
| cetakHelloWorld(n - 1); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // C program for implementation of selection sort | |
| #include <stdio.h> | |
| void selectionSort(int arr[], int n) { | |
| for (int i = 0; i < n - 1; i++) { | |
| // Assume the current position holds | |
| // the minimum element | |
| int min_idx = i; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| // Merges two subarrays of arr[]. | |
| // First subarray is arr[l..m] | |
| // Second subarray is arr[m+1..r] | |
| void merge(int arr[], int l, int m, int r){ | |
| int i, j, k; | |
| int n1 = m - l + 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // C Program to sort an array using qsort() function in C | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| // If a should be placed before b, compare function should | |
| // return positive value, if it should be placed after b, | |
| // it should return negative value. Returns 0 otherwise | |
| int compare(const void* a, const void* b) { | |
| return (*(int*)a - *(int*)b); | |
| } |
NewerOlder