From 60882549596c0207ecfa0a2913261b081ee800da Mon Sep 17 00:00:00 2001 From: a2nr Date: Tue, 5 May 2026 14:09:40 +0700 Subject: [PATCH] fix: ganti '//n' jadi '/n' --- content/arrays.md | 22 +++---- content/arrays_and_pointers.md | 12 ++-- content/binary_trees.md | 4 +- content/conditions.md | 8 +-- content/dynamic_allocation.md | 4 +- content/for_loops.md | 18 ++--- content/function_arguments_by_reference.md | 16 ++--- content/function_pointers.md | 22 +++---- content/functions.md | 2 +- content/hello_world.md | 2 +- content/linked_lists.md | 6 +- content/operators.md | 76 +++++++++++----------- content/pointer_arithmetics.md | 32 ++++----- content/pointers.md | 10 +-- content/recursion.md | 16 ++--- content/strings.md | 22 +++---- content/unions.md | 16 ++--- content/while_loops.md | 32 ++++----- elemes | 2 +- 19 files changed, 161 insertions(+), 161 deletions(-) diff --git a/content/arrays.md b/content/arrays.md index 6a0bedb..f7bec38 100644 --- a/content/arrays.md +++ b/content/arrays.md @@ -98,7 +98,7 @@ for (int i = 0; i < 5; i++) { int myNumbers[5] = {10, 20, 30, 40, 50}; for (int i = 0; i < 5; i++) { - printf("%d\\n", myNumbers[i]); + printf("%d\n", myNumbers[i]); } ``` @@ -124,15 +124,15 @@ int main() { int total = 0; int arraySize = sizeof(scores) / sizeof(scores[0]); - printf("Nilai ujian siswa:\\n"); + printf("Nilai ujian siswa:\n"); for (int i = 0; i < arraySize; i++) { - printf("Siswa %d: %d\\n", i+1, scores[i]); + printf("Siswa %d: %d\n", i+1, scores[i]); total += scores[i]; } float average = (float)total / arraySize; - printf("\\nTotal nilai: %d\\n", total); - printf("Rata-rata nilai: %.2f\\n", average); + printf("\nTotal nilai: %d\n", total); + printf("Rata-rata nilai: %.2f\n", average); return 0; } @@ -229,9 +229,9 @@ int main() { // TODO: Hitung rata-rata float average = 0.0; - printf("Total nilai: %d\\n", total); - printf("Jumlah siswa: %d\\n", count); - printf("Rata-rata nilai: %.2f\\n", average); + printf("Total nilai: %d\n", total); + printf("Jumlah siswa: %d\n", count); + printf("Rata-rata nilai: %.2f\n", average); return 0; } @@ -254,9 +254,9 @@ int main() { // Hitung rata-rata float average = (float)total / count; - printf("Total nilai: %d\\n", total); - printf("Jumlah siswa: %d\\n", count); - printf("Rata-rata nilai: %.2f\\n", average); + printf("Total nilai: %d\n", total); + printf("Jumlah siswa: %d\n", count); + printf("Rata-rata nilai: %.2f\n", average); return 0; } diff --git a/content/arrays_and_pointers.md b/content/arrays_and_pointers.md index b9186f5..a45c317 100644 --- a/content/arrays_and_pointers.md +++ b/content/arrays_and_pointers.md @@ -30,12 +30,12 @@ int i; // Print the addresses for (i = 0; i < 5; i++) { - printf("&vowels[%d]: %p, pvowels + %d: %p, vowels + %d: %p\\n", i, &vowels[i], i, pvowels + i, i, vowels + i); + printf("&vowels[%d]: %p, pvowels + %d: %p, vowels + %d: %p\n", i, &vowels[i], i, pvowels + i, i, vowels + i); } // Print the values for (i = 0; i < 5; i++) { - printf("vowels[%d]: %c, *(pvowels + %d): %c, *(vowels + %d): %c\\n", i, vowels[i], i, *(pvowels + i), i, *(vowels + i)); + printf("vowels[%d]: %c, *(pvowels + %d): %c, *(vowels + %d): %c\n", i, vowels[i], i, *(pvowels + i), i, *(vowels + i)); } ``` @@ -77,7 +77,7 @@ pvowels[3] = 'O'; for (i = 0; i < n; i++) { printf("%c ", pvowels[i]); } -printf("\\n"); +printf("\n"); free(pvowels); ``` @@ -113,7 +113,7 @@ for (i = 0; i < nrows; i++) { for(j = 0; j < ncols; j++) { printf("%c ", pvowels[i][j]); } - printf("\\n"); + printf("\n"); } // Bebaskan baris-baris individu @@ -208,7 +208,7 @@ free(pnumbers) for (j = 0; j <= i; j++) { printf("%d", pnumbers[i][j]); } - printf("\\n"); + printf("\n"); } for (i = 0; i < 3; i++) { @@ -250,7 +250,7 @@ free(pnumbers) for (j = 0; j <= i; j++) { printf("%d", pnumbers[i][j]); } - printf("\\n"); + printf("\n"); } for (i = 0; i < 3; i++) { diff --git a/content/binary_trees.md b/content/binary_trees.md index fd882f6..8006c7e 100644 --- a/content/binary_trees.md +++ b/content/binary_trees.md @@ -93,7 +93,7 @@ int main() { insert(test_list,4); insert(test_list,3); printDFS(test_list); - printf("\\n"); + printf("\n"); } void insert(node_t * tree, int val) { @@ -164,7 +164,7 @@ int main() { insert(test_list,4); insert(test_list,3); printDFS(test_list); - printf("\\n"); + printf("\n"); } void insert(node_t * tree, int val) { diff --git a/content/conditions.md b/content/conditions.md index 55a1408..537d164 100644 --- a/content/conditions.md +++ b/content/conditions.md @@ -170,13 +170,13 @@ int num = 1; switch (num) { case 1: - printf("Nomor 1\\n"); + printf("Nomor 1\n"); case 2: - printf("Nomor 2\\n"); + printf("Nomor 2\n"); case 3: - printf("Nomor 3\\n"); + printf("Nomor 3\n"); default: - printf("Nomor lain\\n"); + printf("Nomor lain\n"); } ``` diff --git a/content/dynamic_allocation.md b/content/dynamic_allocation.md index 8bcb756..9301283 100644 --- a/content/dynamic_allocation.md +++ b/content/dynamic_allocation.md @@ -110,7 +110,7 @@ mypoint coordinates: 10, 5 mypoint->x = 10; mypoint->y =5 ; - printf("mypoint coordinates: %d, %d\\n", mypoint->x, mypoint->y); + printf("mypoint coordinates: %d, %d\n", mypoint->x, mypoint->y); free(mypoint); return 0; } @@ -132,7 +132,7 @@ mypoint coordinates: 10, 5 mypoint->x = 10; mypoint->y =5 ; - printf("mypoint coordinates: %d, %d\\n", mypoint->x, mypoint->y); + printf("mypoint coordinates: %d, %d\n", mypoint->x, mypoint->y); free(mypoint); return 0; } diff --git a/content/for_loops.md b/content/for_loops.md index 702b21d..9071b75 100644 --- a/content/for_loops.md +++ b/content/for_loops.md @@ -61,7 +61,7 @@ int main() { int n = sizeof(numbers) / sizeof(numbers[0]); // menghitung jumlah elemen for (int i = 0; i < n; i++) { - printf("Elemen ke-%d: %d\\n", i, numbers[i]); + printf("Elemen ke-%d: %d\n", i, numbers[i]); } return 0; @@ -90,7 +90,7 @@ int main() { for (int j = 1; j <= i; j++) { printf("* "); } - printf("\\n"); + printf("\n"); } return 0; @@ -144,15 +144,15 @@ int main() { int n = sizeof(scores) / sizeof(scores[0]); int total = 0; - printf("Daftar nilai siswa:\\n"); + printf("Daftar nilai siswa:\n"); for (int i = 0; i < n; i++) { - printf("Siswa %d: %d\\n", i+1, scores[i]); + printf("Siswa %d: %d\n", i+1, scores[i]); total += scores[i]; } float average = (float)total / n; - printf("\\nTotal nilai: %d\\n", total); - printf("Rata-rata nilai: %.2f\\n", average); + printf("\nTotal nilai: %d\n", total); + printf("Rata-rata nilai: %.2f\n", average); return 0; } @@ -251,7 +251,7 @@ Tabel Perkalian 5x5: #include int main() { - printf("Tabel Perkalian 5x5:\\n"); + printf("Tabel Perkalian 5x5:\n"); // TODO: Gunakan nested for loops untuk mencetak tabel perkalian // Baris dan kolom dari 1 hingga 5 @@ -264,13 +264,13 @@ int main() { #include int main() { - printf("Tabel Perkalian 5x5:\\n"); + printf("Tabel Perkalian 5x5:\n"); for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 5; j++) { printf("%-3d", i * j); // %-3d untuk format rata kiri dengan lebar 3 karakter } - printf("\\n"); + printf("\n"); } return 0; diff --git a/content/function_arguments_by_reference.md b/content/function_arguments_by_reference.md index 5cff55d..186c810 100644 --- a/content/function_arguments_by_reference.md +++ b/content/function_arguments_by_reference.md @@ -23,9 +23,9 @@ void addone(int n) { } int n; -printf("Sebelum: %d\\n", n); +printf("Sebelum: %d\n", n); addone(n); -printf("Setelah: %d\\n", n); +printf("Setelah: %d\n", n); ``` Namun, ini akan bekerja: @@ -37,9 +37,9 @@ void addone(int *n) { } int n; -printf("Sebelum: %d\\n", n); +printf("Sebelum: %d\n", n); addone(&n); -printf("Setelah: %d\\n", n); +printf("Setelah: %d\n", n); ``` Perbedaannya adalah versi kedua dari `addone` menerima pointer ke variabel `n` sebagai argumen, dan kemudian bisa memanipulasinya, karena tahu di mana itu berada di memori. Perhatikan bahwa ketika memanggil fungsi `addone`, kita **harus** melewatkan referensi ke variabel `n`, dan bukan variabel itu sendiri - ini dilakukan agar fungsi tahu alamat dari variabel, dan tidak hanya menerima salinan dari variabel itu sendiri. @@ -122,9 +122,9 @@ Happy birthday! John is now 28 years old. person john; john.name = "John"; john.age = 27; - printf("%s is %d years old.\\n", john.name, john.age); + printf("%s is %d years old.\n", john.name, john.age); birthday(&john); - printf("Happy birthday! %s is now %d years old.\\n", john.name, john.age); + printf("Happy birthday! %s is now %d years old.\n", john.name, john.age); return 0; } ---END_INITIAL_CODE--- @@ -149,9 +149,9 @@ Happy birthday! John is now 28 years old. person john; john.name = "John"; john.age = 27; - printf("%s is %d years old.\\n", john.name, john.age); + printf("%s is %d years old.\n", john.name, john.age); birthday(&john); - printf("Happy birthday! %s is now %d years old.\\n", john.name, john.age); + printf("Happy birthday! %s is now %d years old.\n", john.name, john.age); return 0; } ---END_SOLUTION_CODE--- \ No newline at end of file diff --git a/content/function_pointers.md b/content/function_pointers.md index 592048a..9fe9196 100644 --- a/content/function_pointers.md +++ b/content/function_pointers.md @@ -41,17 +41,17 @@ Oke cukup teori. Mari kita coba dengan kode nyata. Lihat contoh ini: #include void someFunction(int arg) { - printf("This is someFunction being called and arg is: %d\\n", arg); - printf("Whoops leaving the function now!\\n"); + printf("This is someFunction being called and arg is: %d\n", arg); + printf("Whoops leaving the function now!\n"); } main() { void (*pf)(int); pf = &someFunction; - printf("We're about to call someFunction() using a pointer!\\n"); + printf("We're about to call someFunction() using a pointer!\n"); (pf)(5); - printf("Wow that was cool. Back to main now!\\n\\n"); + printf("Wow that was cool. Back to main now!\n\n"); } ``` @@ -74,7 +74,7 @@ main() int c = 0; while (c < sizeof(iarray)/sizeof(*iarray)) { - printf("%d \\t", iarray[c]); + printf("%d \t", iarray[c]); c++; } } @@ -130,17 +130,17 @@ this is f3 and var is: 2 #include void f1(int var) { - printf("this is f1 and var is: %d\\n", var); + printf("this is f1 and var is: %d\n", var); } void f2(int var) { - printf("this is f2 and var is: %d\\n", var); + printf("this is f2 and var is: %d\n", var); } void f3(int var) { - printf("this is f3 and var is: %d\\n", var); + printf("this is f3 and var is: %d\n", var); } int main() @@ -160,17 +160,17 @@ int main() #include void f1(int var) { - printf("this is f1 and var is: %d\\n", var); + printf("this is f1 and var is: %d\n", var); } void f2(int var) { - printf("this is f2 and var is: %d\\n", var); + printf("this is f2 and var is: %d\n", var); } void f3(int var) { - printf("this is f3 and var is: %d\\n", var); + printf("this is f3 and var is: %d\n", var); } int main() diff --git a/content/functions.md b/content/functions.md index 22352e8..a4047e0 100644 --- a/content/functions.md +++ b/content/functions.md @@ -146,7 +146,7 @@ printf void print_big(int number){ if(number > 10){ - printf("%d is big\\n",number); + printf("%d is big\n",number); } } ---END_SOLUTION_CODE--- \ No newline at end of file diff --git a/content/hello_world.md b/content/hello_world.md index e7f3d1f..e46a5b6 100644 --- a/content/hello_world.md +++ b/content/hello_world.md @@ -160,7 +160,7 @@ int y = 10; | Fungsi | Deskripsi | Contoh | |--------|-----------|--------| -| printf() | Mencetak output ke layar | `printf("Halo Dunia\\n");` | +| printf() | Mencetak output ke layar | `printf("Halo Dunia\n");` | | scanf() | Membaca input dari pengguna | `scanf("%d", &angka);` | | getchar() | Membaca satu karakter | `char c = getchar();` | | putchar() | Mencetak satu karakter | `putchar('A');` | diff --git a/content/linked_lists.md b/content/linked_lists.md index 02b4e9c..4d75afc 100644 --- a/content/linked_lists.md +++ b/content/linked_lists.md @@ -87,7 +87,7 @@ Mari kita buat fungsi yang mencetak semua item dari daftar. Untuk melakukan ini, void print_list(node_t * head) { node_t * current = head; while (current != NULL) { - printf("%d\\n", current->val); + printf("%d\n", current->val); current = current->next; } } @@ -289,7 +289,7 @@ pop(head) void print_list(node_t * head) { node_t * current = head; while (current != NULL) { - printf("%d\\n", current->val); + printf("%d\n", current->val); current = current->next; } } @@ -343,7 +343,7 @@ pop(head) void print_list(node_t * head) { node_t * current = head; while (current != NULL) { - printf("%d\\n", current->val); + printf("%d\n", current->val); current = current->next; } } diff --git a/content/operators.md b/content/operators.md index fc29dd6..b3eece7 100644 --- a/content/operators.md +++ b/content/operators.md @@ -46,17 +46,17 @@ Contoh: int main() { int a = 10, b = 3; - printf("a + b = %d\\n", a + b); // 13 - printf("a - b = %d\\n", a - b); // 7 - printf("a * b = %d\\n", a * b); // 30 - printf("a / b = %d\\n", a / b); // 3 (pembagian integer) - printf("a %% b = %d\\n", a % b); // 1 (sisa bagi) + printf("a + b = %d\n", a + b); // 13 + printf("a - b = %d\n", a - b); // 7 + printf("a * b = %d\n", a * b); // 30 + printf("a / b = %d\n", a / b); // 3 (pembagian integer) + printf("a %% b = %d\n", a % b); // 1 (sisa bagi) a++; // a sekarang menjadi 11 - printf("a++ = %d\\n", a); // 11 + printf("a++ = %d\n", a); // 11 b--; // b sekarang menjadi 2 - printf("b-- = %d\\n", b); // 2 + printf("b-- = %d\n", b); // 2 return 0; } @@ -81,16 +81,16 @@ Contoh: int main() { int x = 10; - printf("x awal: %d\\n", x); // 10 + printf("x awal: %d\n", x); // 10 x += 5; // Sama dengan x = x + 5 - printf("x += 5: %d\\n", x); // 15 + printf("x += 5: %d\n", x); // 15 x -= 3; // Sama dengan x = x - 3 - printf("x -= 3: %d\\n", x); // 12 + printf("x -= 3: %d\n", x); // 12 x *= 2; // Sama dengan x = x * 2 - printf("x *= 2: %d\\n", x); // 24 + printf("x *= 2: %d\n", x); // 24 return 0; } @@ -116,12 +116,12 @@ Contoh: int main() { int a = 5, b = 10; - printf("a == b: %d\\n", a == b); // 0 (salah) - printf("a != b: %d\\n", a != b); // 1 (benar) - printf("a > b: %d\\n", a > b); // 0 (salah) - printf("a < b: %d\\n", a < b); // 1 (benar) - printf("a >= b: %d\\n", a >= b); // 0 (salah) - printf("a <= b: %d\\n", a <= b); // 1 (benar) + printf("a == b: %d\n", a == b); // 0 (salah) + printf("a != b: %d\n", a != b); // 1 (benar) + printf("a > b: %d\n", a > b); // 0 (salah) + printf("a < b: %d\n", a < b); // 1 (benar) + printf("a >= b: %d\n", a >= b); // 0 (salah) + printf("a <= b: %d\n", a <= b); // 1 (benar) return 0; } @@ -146,17 +146,17 @@ int main() { // AND: Benar jika kedua kondisi benar if (x > 0 && y > 0) { - printf("Kedua angka positif\\n"); // Ditampilkan + printf("Kedua angka positif\n"); // Ditampilkan } // OR: Benar jika salah satu kondisi benar if (x > 10 || y > 5) { - printf("Setidaknya satu angka lebih besar\\n"); // Ditampilkan + printf("Setidaknya satu angka lebih besar\n"); // Ditampilkan } // NOT: Membalikkan kondisi if (!(x == y)) { - printf("x tidak sama dengan y\\n"); // Ditampilkan + printf("x tidak sama dengan y\n"); // Ditampilkan } return 0; @@ -184,10 +184,10 @@ int main() { unsigned char a = 5; // 00000101 unsigned char b = 3; // 00000011 - printf("a & b = %d\\n", a & b); // 1 (00000001) - printf("a | b = %d\\n", a | b); // 7 (00000111) - printf("a ^ b = %d\\n", a ^ b); // 6 (00000110) - printf("~a = %d\\n", ~a); // 250 (11111010 dalam 8-bit) + printf("a & b = %d\n", a & b); // 1 (00000001) + printf("a | b = %d\n", a | b); // 7 (00000111) + printf("a ^ b = %d\n", a ^ b); // 6 (00000110) + printf("~a = %d\n", ~a); // 250 (11111010 dalam 8-bit) return 0; } @@ -213,14 +213,14 @@ int max = (a > b) ? a : b; // Jika a > b maka max = a, jika tidak max = b ### Operator `sizeof` ```c int num; -printf("Ukuran int: %zu byte\\n", sizeof(num)); // Ukuran dalam byte +printf("Ukuran int: %zu byte\n", sizeof(num)); // Ukuran dalam byte ``` ### Operator Alamat (`&`) dan Pointer (`*`) ```c int x = 5; int *ptr = &x; // ptr menyimpan alamat dari x -printf("Nilai x: %d\\n", *ptr); // Mengakses nilai melalui pointer +printf("Nilai x: %d\n", *ptr); // Mengakses nilai melalui pointer ``` ## Urutan Prioritas Operator @@ -255,11 +255,11 @@ int main() { // Perkalian dilakukan dulu karena prioritas lebih tinggi result = a + b * c; // Sama dengan a + (b * c) = 5 + 30 = 35 - printf("a + b * c = %d\\n", result); + printf("a + b * c = %d\n", result); // Gunakan kurung untuk mengganti urutan prioritas result = (a + b) * c; // Sama dengan (a + b) * c = 15 * 3 = 45 - printf("(a + b) * c = %d\\n", result); + printf("(a + b) * c = %d\n", result); return 0; } @@ -280,22 +280,22 @@ int main() { // Menggunakan operator logika dan perbandingan if (age >= 18 && has_license) { - printf("Anda bisa mengemudi\\n"); + printf("Anda bisa mengemudi\n"); } // Menggunakan operator aritmatika dan penugasan score += bonus; // Menambahkan bonus ke skor - printf("Skor akhir: %d\\n", score); + printf("Skor akhir: %d\n", score); // Menggunakan operator conditional char *status = (score >= 75) ? "Lulus" : "Tidak Lulus"; - printf("Status: %s\\n", status); + printf("Status: %s\n", status); // Menggunakan operator modulo untuk mengecek genap/ganjil if (score % 2 == 0) { - printf("Skor adalah bilangan genap\\n"); + printf("Skor adalah bilangan genap\n"); } else { - printf("Skor adalah bilangan ganjil\\n"); + printf("Skor adalah bilangan ganjil\n"); } return 0; @@ -381,23 +381,23 @@ int main() { // Penjumlahan hasil = a + b; - printf("Hasil penjumlahan: %d\\n", hasil); + printf("Hasil penjumlahan: %d\n", hasil); // Pengurangan hasil = a - b; - printf("Hasil pengurangan: %d\\n", hasil); + printf("Hasil pengurangan: %d\n", hasil); // Perkalian hasil = a * b; - printf("Hasil perkalian: %d\\n", hasil); + printf("Hasil perkalian: %d\n", hasil); // Pembagian hasil = a / b; - printf("Hasil pembagian: %d\\n", hasil); + printf("Hasil pembagian: %d\n", hasil); // Modulo hasil = a % b; - printf("Sisa hasil bagi: %d\\n", hasil); + printf("Sisa hasil bagi: %d\n", hasil); return 0; } diff --git a/content/pointer_arithmetics.md b/content/pointer_arithmetics.md index febc7ad..2858c86 100644 --- a/content/pointer_arithmetics.md +++ b/content/pointer_arithmetics.md @@ -29,12 +29,12 @@ int main() { int intarray[5] = {10,20,30,40,50}; int i; for(i = 0; i < 5; i++) - printf("intarray[%d] has value %d - and address @ %x\\n", i, intarray[i], &intarray[i]); + printf("intarray[%d] has value %d - and address @ %x\n", i, intarray[i], &intarray[i]); int *intpointer = &intarray[3]; //point to the 4th element in the array - printf("address: %x - has value %d\\n", intpointer, *intpointer); //print the address of the 4th element + printf("address: %x - has value %d\n", intpointer, *intpointer); //print the address of the 4th element intpointer++; //now increase the pointer's address so it points to the 5th elemnt in the array - printf("address: %x - has value %d\\n", intpointer, *intpointer); //print the address of the 5th element + printf("address: %x - has value %d\n", intpointer, *intpointer); //print the address of the 5th element return 0; } ``` @@ -50,12 +50,12 @@ int main() { int intarray[5] = {10,20,30,40,50}; int i; for(i = 0; i < 5; i++) - printf("intarray[%d] has value %d - and address @ %x\\n", i, intarray[i], &intarray[i]); + printf("intarray[%d] has value %d - and address @ %x\n", i, intarray[i], &intarray[i]); int *intpointer = &intarray[4]; //point to the 5th element in the array - printf("address: %x - has value %d\\n", intpointer, *intpointer); //print the address of the 5th element + printf("address: %x - has value %d\n", intpointer, *intpointer); //print the address of the 5th element intpointer--; //now decrease the point's address so it points to the 4th element in the array - printf("address: %x - has value %d\\n", intpointer, *intpointer); //print the address of the 4th element + printf("address: %x - has value %d\n", intpointer, *intpointer); //print the address of the 4th element return 0; } ``` @@ -71,12 +71,12 @@ int main() { int intarray[5] = {10,20,30,40,50}; int i; for(i = 0; i < 5; i++) - printf("intarray[%d] has value: %d - and address @ %x\\n", i, intarray[i], &intarray[i]); + printf("intarray[%d] has value: %d - and address @ %x\n", i, intarray[i], &intarray[i]); int *intpointer = &intarray[1]; //point to the 2nd element in the array - printf("address: %x - has value %d\\n", intpointer, *intpointer); //print the address of the 2nd element + printf("address: %x - has value %d\n", intpointer, *intpointer); //print the address of the 2nd element intpointer += 2; //now shift by two the point's address so it points to the 4th element in the array - printf("address: %x - has value %d\\n", intpointer, *intpointer); //print the addres of the 4th element + printf("address: %x - has value %d\n", intpointer, *intpointer); //print the addres of the 4th element return 0; } ``` @@ -94,12 +94,12 @@ int main() { int intarray[5] = {10,20,30,40,50}; int i; for(i = 0; i < 5; i++) - printf("intarray[%d] has value: %d - and address @ %x\\n", i, intarray[i], &intarray[i]); + printf("intarray[%d] has value: %d - and address @ %x\n", i, intarray[i], &intarray[i]); int *intpointer = &intarray[4]; //point to the 5th element in the array - printf("address: %x - has value %d\\n", intpointer, *intpointer); //print the address of the 5th element + printf("address: %x - has value %d\n", intpointer, *intpointer); //print the address of the 5th element intpointer -= 2; //now shift by two the point's address so it points to the 3rd element in the array - printf("address: %x - has value %d\\n", intpointer, *intpointer); //print the address of the 3rd element + printf("address: %x - has value %d\n", intpointer, *intpointer); //print the address of the 3rd element return 0; } ``` @@ -175,9 +175,9 @@ int main() { // Test code for (i = 0; i < 3; i++) { if (parray[i] == &pointer[i]) { - printf("Matched!\\n"); + printf("Matched!\n"); } else { - printf("Fail\\n"); + printf("Fail\n"); } } return 0; @@ -200,9 +200,9 @@ int main() { for (i = 0; i < 3; i++) { if (parray[i] == &pointer[i]) { - printf("Matched!\\n"); + printf("Matched!\n"); } else { - printf("Fail\\n"); + printf("Fail\n"); } } return 0; diff --git a/content/pointers.md b/content/pointers.md index 1656308..7b21b91 100644 --- a/content/pointers.md +++ b/content/pointers.md @@ -62,8 +62,8 @@ int a = 1; /* definisikan variabel pointer, dan arahkan ke a menggunakan operator & */ int * pointer_to_a = &a; -printf("Nilai a adalah %d\\n", a); -printf("Nilai a juga %d\\n", *pointer_to_a); +printf("Nilai a adalah %d\n", a); +printf("Nilai a juga %d\n", *pointer_to_a); ``` Perhatikan bahwa kita menggunakan operator `&` untuk menunjuk ke variabel `a`, yang baru saja kita buat. Kita kemudian merujuk ke variabel tersebut menggunakan operator dereferencing. @@ -81,7 +81,7 @@ a += 1; *pointer_to_a += 1; /* akan mencetak 3 */ -printf("Nilai dari a sekarang %d\\n", a); +printf("Nilai dari a sekarang %d\n", a); ``` --- @@ -135,7 +135,7 @@ int main() { /* pengujian kode */ if (pointer_to_n != &n) return 1; if (*pointer_to_n != 11) return 1; - printf("Done!\\n"); + printf("Done!\n"); return 0; } ---END_INITIAL_CODE--- @@ -151,7 +151,7 @@ int main() { /* pengujian kode */ if (pointer_to_n != &n) return 1; if (*pointer_to_n != 11) return 1; - printf("Done!\\n"); + printf("Done!\n"); return 0; } ---END_SOLUTION_CODE--- \ No newline at end of file diff --git a/content/recursion.md b/content/recursion.md index cec0ebb..21778c4 100644 --- a/content/recursion.md +++ b/content/recursion.md @@ -101,10 +101,10 @@ int factorial int main() { /* kode pengujian */ - printf("0! = %i\\n", factorial(0)); - printf("1! = %i\\n", factorial(1)); - printf("3! = %i\\n", factorial(3)); - printf("5! = %i\\n", factorial(5)); + printf("0! = %i\n", factorial(0)); + printf("1! = %i\n", factorial(1)); + printf("3! = %i\n", factorial(3)); + printf("5! = %i\n", factorial(5)); } /* definisikan fungsi Anda di sini (jangan lupa untuk deklarasikan) */ @@ -118,10 +118,10 @@ int factorial int main() { /* kode pengujian */ - printf("0! = %i\\n", factorial(0)); - printf("1! = %i\\n", factorial(1)); - printf("3! = %i\\n", factorial(3)); - printf("5! = %i\\n", factorial(5)); + printf("0! = %i\n", factorial(0)); + printf("1! = %i\n", factorial(1)); + printf("3! = %i\n", factorial(3)); + printf("5! = %i\n", factorial(5)); } int factorial(int number) diff --git a/content/strings.md b/content/strings.md index 49b7f58..9f1a848 100644 --- a/content/strings.md +++ b/content/strings.md @@ -41,17 +41,17 @@ Kita bisa menggunakan perintah `printf` untuk memformat string bersama dengan st char * name = "John Smith"; int age = 27; /* mencetak 'John Smith is 27 years old.' */ -printf("%s is %d years old.\\n", name, age); +printf("%s is %d years old.\n", name, age); ``` -Perhatikan bahwa ketika mencetak string, kita harus menambahkan karakter baris baru (`\\n`) sehingga perintah `printf` berikutnya akan mencetak di baris baru. +Perhatikan bahwa ketika mencetak string, kita harus menambahkan karakter baris baru (`\n`) sehingga perintah `printf` berikutnya akan mencetak di baris baru. ## Panjang String Fungsi 'strlen' mengembalikan panjang string yang harus dilewatkan sebagai argumen: ```c char * name = "Nikhil"; -printf("%d\\n",strlen(name)); +printf("%d\n",strlen(name)); ``` ## Perbandingan String @@ -60,9 +60,9 @@ Fungsi `strncmp` membandingkan antara dua string, mengembalikan angka 0 jika mer ```c char * name = "John"; if (strncmp(name, "John", 4) == 0) { - printf("Hello, John!\\n"); + printf("Hello, John!\n"); } else { - printf("You are not John. Go away.\\n"); + printf("You are not John. Go away.\n"); } ``` @@ -73,9 +73,9 @@ Fungsi 'strncat' menambahkan n karakter pertama dari string src ke string tujuan char dest[20]="Hello"; char src[20]="World"; strncat(dest,src,3); -printf("%s\\n",dest); +printf("%s\n",dest); strncat(dest,src,20); -printf("%s\\n",dest); +printf("%s\n",dest); ``` --- @@ -134,12 +134,12 @@ int main() { last_name[0] = 'B'; sprintf(name, "%s %s", first_name, last_name); if (strncmp(name, "John Boe", 100) == 0) { - printf("Done!\\n"); + printf("Done!\n"); } name[0]='\0'; strncat(name,first_name,4); strncat(name,last_name,20); - printf("%s\\n",name); + printf("%s\n",name); return 0; } ---END_INITIAL_CODE--- @@ -155,12 +155,12 @@ int main() { last_name[0] = 'B'; sprintf(name, "%s %s", first_name, last_name); if (strncmp(name, "John Boe", 100) == 0) { - printf("Done!\\n"); + printf("Done!\n"); } name[0]='\0'; strncat(name,first_name,4); strncat(name,last_name,20); - printf("%s\\n",name); + printf("%s\n",name); return 0; } ---END_SOLUTION_CODE--- \ No newline at end of file diff --git a/content/unions.md b/content/unions.md index f45d1e3..8464629 100644 --- a/content/unions.md +++ b/content/unions.md @@ -26,12 +26,12 @@ Memungkinkan Anda untuk melihat setiap byte secara individual tanpa casting poin ```c union intParts parts; parts.theInt = 5968145; // angka acak > 255 (1 byte) -printf("The int is %i\\nThe bytes are [%i, %i, %i, %i]\\n", parts.theInt, parts.bytes[0], parts.bytes[1], parts.bytes[2], parts.bytes[3]); +printf("The int is %i\nThe bytes are [%i, %i, %i, %i]\n", parts.theInt, parts.bytes[0], parts.bytes[1], parts.bytes[2], parts.bytes[3]); // vs int theInt = parts.theInt; -printf("The int is %i\\nThe bytes are [%i, %i, %i, %i]\\n", theInt, *((char*)&theInt+0), *((char*)&theInt+1), *((char*)&theInt+2), *((char*)&theInt+3)); +printf("The int is %i\nThe bytes are [%i, %i, %i, %i]\n", theInt, *((char*)&theInt+0), *((char*)&theInt+1), *((char*)&theInt+2), *((char*)&theInt+3)); // atau dengan sintaks array yang bisa sedikit lebih enak terkadang -printf("The int is %i\\nThe bytes are [%i, %i, %i, %i]\\n", theInt, ((char*)&theInt)[0], ((char*)&theInt)[1], ((char*)&theInt)[2], ((char*)&theInt)[3]); +printf("The int is %i\nThe bytes are [%i, %i, %i, %i]\n", theInt, ((char*)&theInt)[0], ((char*)&theInt)[1], ((char*)&theInt)[2], ((char*)&theInt)[3]); ``` Menggabungkan ini dengan struktur memungkinkan Anda membuat union "bertag" yang bisa digunakan untuk menyimpan beberapa tipe berbeda, satu per satu. Sebagai contoh, Anda mungkin memiliki struktur "number", tetapi Anda tidak ingin menggunakan sesuatu seperti ini: @@ -105,7 +105,7 @@ union Coins change; for(int i = 0; i < sizeof(change) / sizeof(int); ++i) { scanf("%i", change.coins + i); // kode BURUK! input selalu mencurigakan! } -printf("There are %i quarters, %i dimes, %i nickels, and %i pennies\\n", change.quarter, change.dime, change.nickel, change.penny); +printf("There are %i quarters, %i dimes, %i nickels, and %i pennies\n", change.quarter, change.dime, change.nickel, change.penny); ``` --- @@ -163,8 +163,8 @@ int main() { // hanya pergi ke 18 karena 1 byte untuk terminasi 0 dan kita tidak mencetak yang terakhir dalam loop for(int i = 0; i < 19; ++i) printf("%c, ", intCharacters.chars[i]); - printf("%c]\\n", intCharacters.chars[19]); - printf("%s\\n", intCharacters.chars); + printf("%c]\n", intCharacters.chars[19]); + printf("%s\n", intCharacters.chars); } ---END_INITIAL_CODE--- @@ -181,7 +181,7 @@ int main() { // hanya pergi ke 18 karena 1 byte untuk terminasi 0 dan kita tidak mencetak yang terakhir dalam loop for(int i = 0; i < 19; ++i) printf("%c, ", intCharacters.chars[i]); - printf("%c]\\n", intCharacters.chars[19]); - printf("%s\\n", intCharacters.chars); + printf("%c]\n", intCharacters.chars[19]); + printf("%s\n", intCharacters.chars); } ---END_SOLUTION_CODE--- \ No newline at end of file diff --git a/content/while_loops.md b/content/while_loops.md index 216f9af..991938e 100644 --- a/content/while_loops.md +++ b/content/while_loops.md @@ -53,7 +53,7 @@ Jika kondisi dalam perulangan while selalu benar, maka perulangan akan berjalan ```c while (1) { - printf("Loop tak terbatas\\n"); + printf("Loop tak terbatas\n"); // Perulangan ini akan berjalan selamanya } ``` @@ -121,12 +121,12 @@ int main() { attempts++; if (password == 1234) { - printf("Password benar! Akses diberikan.\\n"); + printf("Password benar! Akses diberikan.\n"); break; } else if (attempts < MAX_ATTEMPTS) { printf("Password salah! Coba lagi (%d kesempatan tersisa): ", MAX_ATTEMPTS - attempts); } else { - printf("Terlalu banyak percobaan salah. Akses ditolak.\\n"); + printf("Terlalu banyak percobaan salah. Akses ditolak.\n"); } } @@ -197,12 +197,12 @@ int i = 10; // While loop - tidak akan mengeksekusi blok kode while (i < 5) { - printf("Ini tidak akan dicetak\\n"); + printf("Ini tidak akan dicetak\n"); } // Do-while loop - akan mengeksekusi blok kode sekali do { - printf("Ini akan dicetak sekali\\n"); + printf("Ini akan dicetak sekali\n"); } while (i < 5); ``` @@ -225,12 +225,12 @@ int main() { attempts++; if (password == 1234) { - printf("Password benar! Akses diberikan.\\n"); + printf("Password benar! Akses diberikan.\n"); break; } else if (attempts < MAX_ATTEMPTS) { printf("Password salah! Coba lagi (%d kesempatan tersisa): ", MAX_ATTEMPTS - attempts); } else { - printf("Terlalu banyak percobaan salah. Akses ditolak.\\n"); + printf("Terlalu banyak percobaan salah. Akses ditolak.\n"); } } @@ -249,25 +249,25 @@ int main() { int choice; do { - printf("\\nMenu:\\n"); - printf("1. Tampilkan pesan\\n"); - printf("2. Hitung angka\\n"); - printf("3. Keluar\\n"); + printf("\nMenu:\n"); + printf("1. Tampilkan pesan\n"); + printf("2. Hitung angka\n"); + printf("3. Keluar\n"); printf("Pilih opsi (1-3): "); scanf("%d", &choice); switch (choice) { case 1: - printf("Anda memilih untuk menampilkan pesan.\\n"); + printf("Anda memilih untuk menampilkan pesan.\n"); break; case 2: - printf("Anda memilih untuk menghitung angka.\\n"); + printf("Anda memilih untuk menghitung angka.\n"); break; case 3: - printf("Keluar dari program.\\n"); + printf("Keluar dari program.\n"); break; default: - printf("Opsi tidak valid. Silakan coba lagi.\\n"); + printf("Opsi tidak valid. Silakan coba lagi.\n"); } } while (choice != 3); @@ -343,7 +343,7 @@ int main() { number++; // Tambahkan number setiap iterasi } - printf("\\n"); + printf("\n"); return 0; } ---END_SOLUTION_CODE--- diff --git a/elemes b/elemes index 2505cd0..a124cf5 160000 --- a/elemes +++ b/elemes @@ -1 +1 @@ -Subproject commit 2505cd0977abbd7194ab44dfe7e75e362a9d889e +Subproject commit a124cf5e6d7ae07d7758a35172afa3e15dd20f9c