Samples
Complete programs that pass the checker, in roughly the order the course teaches them. Open one in the editor to run it, then choose Edit a copy to change it.
Hello
Asks for your name with input() and prints a greeting.
Asks you for input when it runs.
Open in the editorprogram halo kamus nama : string algoritma output("Siapa namamu?") input(nama) output("Halo, " + nama + "!") endprogramInput
Reads two integers and prints their sum, difference, product, div, and mod.
Asks you for input when it runs.
Open in the editorprogram aritmetika_input kamus a, b : integer algoritma output("Masukkan dua bilangan bulat:") input(a, b) output("Jumlah:", a + b) output("Selisih:", a - b) output("Kali:", a * b) output("Bagi (div):", a div b) output("Sisa (mod):", a mod b) endprogram-
program alur_kendali kamus nilai, i, jumlah : integer algoritma nilai = 3 if nilai > 5 then output("besar") else if nilai == 3 then output("tiga") else output("kecil") endif case nilai of 1: output("satu") 2, 3: output("dua atau tiga") else: output("lainnya") endcase jumlah = 0 for i = 1 to 5 do jumlah = jumlah + i endfor output("jumlah for:", jumlah) while jumlah > 0 do jumlah = jumlah - 3 endwhile output("sisa while:", jumlah) repeat jumlah = jumlah + 1 until jumlah >= 3 output("hasil repeat:", jumlah) endprogram -
program larik kamus constant N : integer = 5 arr : array[0..N-1] of integer i, jumlah, maks : integer algoritma for i = 0 to N - 1 do arr[i] = (i + 1) * 10 endfor jumlah = 0 maks = arr[0] i = 0 while i < N do jumlah = jumlah + arr[i] if arr[i] > maks then maks = arr[i] endif i = i + 1 endwhile output("jumlah:", jumlah) output("maksimum:", maks) endprogram Strings
Shows string length, character indexing, character replacement, and concatenation.
Open in the editorprogram olah_string kamus s : string c : char algoritma s = "telkom" output("panjang:", len(s)) c = s[1] output("indeks 1:", c) s[0] = "T" output("ubah:", s) output("gabung:", s + " Bandung") endprogramStructs
Defines a record type with fields and stores multiple records in an array.
Open in the editorprogram tipe_bentukan kamus type Mahasiswa : < nama : string, umur : integer > daftar : array[0..1] of Mahasiswa i : integer algoritma daftar[0].nama = "Aep" daftar[0].umur = 20 daftar[1].nama = "Siti" daftar[1].umur = 19 for i = 0 to 1 do output(daftar[i].nama, daftar[i].umur) endfor endprogramProcedures
Passes variables by reference using in/out parameters to swap and increment values.
Open in the editorprogram prosedur_tukar kamus a, b : integer algoritma a = 10 b = 20 output("sebelum:", a, b) tukar(a, b) output("sesudah:", a, b) tambah_satu(a) output("ditambah 1:", a) endprogram procedure tukar(in/out x, in/out y : integer) { I.S. x dan y terdefinisi F.S. nilai x dan y bertukar } kamus t : integer algoritma t = x x = y y = t endprocedure procedure tambah_satu(in/out v : integer) { I.S. v terdefinisi F.S. v bertambah 1 } algoritma v = v + 1 endprocedure-
program rekursi kamus n : integer algoritma n = 6 output("faktorial:", faktorial(n)) output("fibonacci:", fibonacci(n)) endprogram function faktorial(n : integer) -> integer { Mengembalikan nilai n! secara rekursif } algoritma if n <= 1 then return 1 endif return n * faktorial(n - 1) endfunction function fibonacci(n : integer) -> integer { Mengembalikan suku ke-n barisan Fibonacci secara rekursif } algoritma if n <= 1 then return n endif return fibonacci(n - 1) + fibonacci(n - 2) endfunction Linked list
Builds a singly linked list with allocate, traverses and searches it, and frees all nodes.
Open in the editorprogram senarai_berantai kamus type Infotype : integer type Address : pointer to ElmList type ElmList : < info : Infotype, next : Address > type List : < first : Address > L : List p, q : Address jumlah : integer algoritma Create_List(L) p = New_Element(10) L.first = p q = New_Element(20) p->next = q p = New_Element(30) q->next = p jumlah = 0 p = L.first while p != NIL do output("isi:", p->info) jumlah = jumlah + p->info p = p->next endwhile output("jumlah:", jumlah) output("ada 20:", search(L, 20) != NIL) p = L.first while p != NIL do q = p->next deallocate(p) p = q endwhile L.first = NIL endprogram procedure Create_List(in/out L : List) { I.S. - F.S. Pointer first dari List L bernilai NIL } algoritma L.first = NIL endprocedure function New_Element(data : Infotype) -> Address { Mengembalikan pointer ke elemen baru teralokasi } kamus p : Address algoritma allocate(p) p->info = data p->next = NIL return p endfunction function search(L : List, v : Infotype) -> Address { Mengembalikan pointer ke elemen berisi v jika ditemukan, atau NIL jika tidak ada } kamus p : Address algoritma p = L.first while p != NIL and p->info != v do p = p->next endwhile return p endfunction