Contoh Latihan Programming (bagian 1)
Latihan Hello World
1. Hello World
Notasi Algoritma:
|
JUDUL: Program helloWorld { Menulis hello world } |
|
KAMUS: { Tidak ada } |
|
DESKRIPSI (ALGORITMA) output("Hello World") |
Code C++:
//JUDUL: Menulis hello world #include <iostream> using namespace std; int main() { //KAMUS: Tidak ada //DESKRIPSI (ALGORITMA) cout << "Hello World" << endl; return 0; }
Hasil Code:
Hello World
2. Hello World (bervariable)
Notasi Algoritma
JUDUL: Program helloWorld { Mengoutputkan hello world memakai variabel } |
KAMUS: say : string |
DESKRIPSI (ALGORITMA) say ← ("Hello World") output(say) |
Code C++:
//JUDUL: Menulis hello world #include <iostream> using namespace std; int main() { //KAMUS string say; //DESKRIPSI (ALGORITMA) say = "Hello World"; cout << say << endl; return 0; }
Hasil Code:
Hello World
3. Hello World (dengan prosedur)
Notasi Algoritma
JUDUL: Program helloWorld { Menulis hello world } |
KAMUS GLOBAL: procedure say() |
DESKRIPSI UTAMA (ALGORITMA): say() |
procedure say() { Prosedur untuk menulis hello world } |
KAMUS LOKAL: { Tidak ada } |
DESKRIPSI (ALGORITMA): output("Hello World") |
Code C++:
//JUDUL: Menulis hello world #include <iostream> using namespace std; //KAMUS GLOBAL: Tidak ada //DESKRIPSI //Judul: Prosedur untuk menulis hello world //procedure say() void say(){ //KAMUS LOKAL: Tidak ada //DESKRIPSI cout << "Hello World"; } int main() { say(); return 0; }
Hasil Code:
Hello World
4. Hello World (dengan prosedur berparameter)
Notasi Algoritma:
JUDUL: Program helloWorld { Menulis hello world } |
KAMUS GLOBAL: kalimat : string procedure say(bilang : string) |
DESKRIPSI UTAMA (ALGORITMA): say(kalimat) |
procedure say(bilang : string) { Prosedur berparameter untuk menulis hello world } |
KAMUS LOKAL: { Tidak ada } |
DESKRIPSI (ALGORITMA): bilang ← ("Hello World") output(bilang) |
Code C++:
//JUDUL: Menulis hello world #include <iostream> using namespace std; //KAMUS GLOBAL string kalimat; //DESKRIPSI UTAMA (ALGORITMA) //JUDUL: Prosedur berparameter untuk menulis hello world //procedure say(bilang : string) void say(string bilang){ //KAMUS LOKAL: Tidak ada //DESKRIPSI bilang = "Hello World"; cout << bilang; } int main() { say(kalimat); return 0; }
Hasil Code:
Hello World
5. Hello World (dengan function berparameter)Notasi Algoritma:
JUDUL: Program helloWorld { Menulis hello world } |
KAMUS GLOBAL: kalimat : string function say(bilang : string) → string |
DESKRIPSI UTAMA (ALGORITMA): say(kalimat) |
function say(bilang : string) → string { Fungsi berparameter untuk menulis hello world } |
KAMUS LOKAL: { Tidak ada } |
DESKRIPSI (ALGORITMA): bilang ← ("Hello World") output(bilang) return bilang |
Code C++:
//JUDUL: Menulis hello world #include <iostream> using namespace std; //KAMUS GLOBAL string kalimat; //DESKRIPSI UTAMA (ALGORITMA) //JUDUL: Fungsi berparameter untuk menulis hello world //function say(bilang : string) -> string string say(string bilang){ //KAMUS LOKAL: Tidak ada //DESKRIPSI bilang = "Hello World"; cout << bilang; return bilang; } int main() { say(kalimat); return 0; }
Hasil Code:
Hello World
Komentar
Posting Komentar