(Pascal) Pattern Script
Yak, kembali ke tu... AAAAAARRRGGGHHH!!! Emang tugas sih, tapi ini sebenernya juga buat pelampiasan rasa penasaran lol. Bikin segitiga gini aja ternyata logikanya ribet bener, pake bahasa jadul pula. Yah, untuk melampiaskan rasa puas, maka saya akan share skrip perulangan bahasa pascal untuk membuat pattern-pattern tertentu. Selengkapnya bisa dilihat dibawah.
- Piramida Ber-spasi (?)
Sumber : programmingsimplified.com (Aslinya dari C++)
Output :
1. For ... do
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | program piramida_bintang; uses crt; var c,j,k : integer; const n : integer = 3; space : integer = 3; count : integer = 1; begin for c := 1 to n do begin for j := 1 to space do write(' '); for k := 1 to c do begin write('*'); if c > 1 then if count < c then begin write(' '); count := count + 1; end; end; writeln; space := space - 1; count := 1; end; readln; end. |
2. While ... do
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | program noname; var c,j,k : integer; const n : integer = 3; space : integer = 3; count : integer = 1; begin c := 1; j := 1; k := 1; while c <= n do begin while j <= space do begin write(' '); j := j + 1; end; while k <= c do begin write('*'); if c > 1 then if count <= c then begin write(' '); count := count + 1; end; k := k + 1; end; j := 1; writeln; space := space - 1; count := 1; c := c + 1; k := 1; end; readln; end. |
3. Repeat ... until
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | program jew; var c,j,k : integer; const n : integer = 3; space : integer = 3; count : integer = 1; begin c := 1; j := 1; k := 1; repeat begin repeat begin write(' '); j := j + 1; end; until j > space; j := 1; repeat begin write('*'); if c > 1 then if count <= c then begin write(' '); count := count + 1; end; k := k + 1; end; until k > c; writeln; space := space - 1; count := 1; c := c + 1; k := 1; end; until c > 3; readln; end. |
*Will be updated soon*
0 komentar:
Post a Comment