coba deh di bahasa pemrogaman Pascal [sumber: rahmat azharis, rafsanjani]
Segitiga Piramid Bintang Rapat
-----------------------------------------------
var
n,i,spasi,bintang : integer;
begin
readln(n);
for i := 1 to n do
begin
for spasi := 1 to n-i do
write(' ');
for bintang := 1 to i*2-1 do
write('*');
writeln;
end;
end.
Segitiga Piramid Bintang Jarang
------------------------------------------------
Contoh input :
10
Contoh output :
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
Source code :
--------------------
var
n,i,spasi,bintang : integer;
begin
readln(n);
for i := 1 to n do
begin
for spasi := 1 to n-i do
write(' ');
for bintang := 1 to i do
write('* ');
writeln;
end;
end.
-------------------------------------------------
Segitiga Siku-Siku Angka Berurut
-------------------------------------------------
Contoh input :
5
Contoh output :
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Source code :
-----------------------
var
n,i,j : integer;
begin
readln(n);
for i := 1 to n do
begin
for j := 1 to i do
write(j,' ');
writeln;
end;
end.
--------------------------------------------------------------
Segitiga Siku-Siku Terbalik Angka Berurut
--------------------------------------------------------------
Contoh input :
5
Contoh output :
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Source code :
---------------------
var
n,i,j : integer;
begin
readln(n);
for i := n downto 1 do
begin
for j := 1 to i do
write(j,' ');
writeln;
end;
end.
-----------------------------------------------
var
n,i,spasi,bintang : integer;
begin
readln(n);
for i := 1 to n do
begin
for spasi := 1 to n-i do
write(' ');
for bintang := 1 to i*2-1 do
write('*');
writeln;
end;
end.
Segitiga Piramid Bintang Jarang
------------------------------------------------
Contoh input :
10
Contoh output :
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
Source code :
--------------------
var
n,i,spasi,bintang : integer;
begin
readln(n);
for i := 1 to n do
begin
for spasi := 1 to n-i do
write(' ');
for bintang := 1 to i do
write('* ');
writeln;
end;
end.
-------------------------------------------------
Segitiga Siku-Siku Angka Berurut
-------------------------------------------------
Contoh input :
5
Contoh output :
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Source code :
-----------------------
var
n,i,j : integer;
begin
readln(n);
for i := 1 to n do
begin
for j := 1 to i do
write(j,' ');
writeln;
end;
end.
--------------------------------------------------------------
Segitiga Siku-Siku Terbalik Angka Berurut
--------------------------------------------------------------
Contoh input :
5
Contoh output :
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Source code :
---------------------
var
n,i,j : integer;
begin
readln(n);
for i := n downto 1 do
begin
for j := 1 to i do
write(j,' ');
writeln;
end;
end.
Komentar
Posting Komentar