Minggu, Agustus 07, 2016

Pascal Programming Convert Decimal (Base 10) to Ternary (Base 3)

uses crt;
var
 a,b,d,e:integer;
 c:array [1..255] of integer;

begin
clrscr;
write('input a decimal number! '); readln(a);
write('ternary of decimal ',a,' is: ');

repeat
b:=b+1;
c[b]:=a mod 3;
d:=trunc(a/3);

if (d<=2) then
 begin
 b:=b+1;
 c[b]:=d;
 end;
a:=d;
until d<=2;

for e:=b downto 1 do
 begin
 write(c[e]);
 end;

readln
end.

please check at http://www.convertworld.com/id/angka/Desimal.html

0 komentar: