Created
December 21, 2010 11:28
-
-
Save sakti/749820 to your computer and use it in GitHub Desktop.
program pencacah bilangan menggunakan pascal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program pencacah; | |
uses crt; | |
var | |
input : longint; | |
function ubah(n : integer; singkat:boolean):string; | |
var | |
hasil:string; | |
ratus,puluh,level,tmp:integer; | |
selesai:boolean; | |
begin | |
hasil:='';selesai:=false;level:=0; | |
ratus:=n div 100; | |
n:=n mod 100; | |
puluh:=n div 10; | |
n:= n mod 10; | |
tmp:=n; | |
while(not selesai)do | |
begin | |
level:=level+1; | |
case level of | |
1: if((puluh=1) and (n<>0))then hasil:= 'belas ' + hasil; | |
2: begin | |
if((puluh>1)or ((puluh=1) and (n=0)))then hasil:= 'puluh ' + hasil; | |
tmp:=puluh; | |
end; | |
3: begin | |
if(ratus<>0)then hasil:= 'ratus ' + hasil; | |
tmp:=ratus; | |
selesai:=true; | |
end; | |
end; | |
if((level=2) and (puluh=1) and (n<>0)) then continue; | |
case tmp of | |
1: if((n=0) or (level=3) or ((n=1) and (puluh=1)))then | |
hasil:= 'se' + hasil | |
else | |
hasil:= 'satu ' + hasil; | |
2: hasil:= 'dua ' + hasil; | |
3: hasil:= 'tiga ' + hasil; | |
4: hasil:= 'empat ' + hasil; | |
5: hasil:= 'lima ' + hasil; | |
6: hasil:= 'enam ' + hasil; | |
7: hasil:= 'tujuh ' + hasil; | |
8: hasil:= 'delapan ' + hasil; | |
9: hasil:= 'sembilan ' + hasil; | |
end; | |
end; | |
if(singkat and (hasil='satu ')) then hasil:='se'; | |
ubah:=hasil; | |
end; | |
function cacah(n : longint):string; | |
var | |
hasil:string; | |
milyar,juta,ribu:integer; | |
begin | |
hasil:=''; | |
milyar:=n div 1000000000; | |
n:=n mod 1000000000; | |
juta:=n div 1000000; | |
n:=n mod 1000000; | |
ribu:=n div 1000; | |
n:=n mod 1000; | |
if(milyar<>0) then hasil:= hasil + ubah(milyar,false) + 'milyar '; | |
if(juta<>0) then hasil:= hasil + ubah(juta,false) + 'juta '; | |
if(ribu<>0) then hasil:= hasil + ubah(ribu,true) + 'ribu '; | |
if(n<>0) then hasil:= hasil + ubah(n,false); | |
cacah:=hasil; | |
end; | |
begin | |
clrscr; | |
write('Masukkan inputan anda : '); | |
readln(input); | |
writeln(cacah(input)); | |
readln; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment