Turns the number from the left to the right

Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
Category: Homework in Pascal

Program: Cnaopak.pas
File exe: Cnaopak.exe
File ubuntu: Cnaopak

Turns the number from the left to the right. It uses mathematical operations instead of a transfer onto a string.
{ CNAOPAK.PAS               Copyright (c) TrSek alias Zdeno Sekerak }
{ Otoci cislo naopak                                                }
{ Vstup : cele cislo (149)                                          }
{ Vystup: cislo s ciframi odzadu (941)                              }
{                                                                   }
{ Datum:10.04.2000                             http://www.trsek.com }
 
program cnaopak(input,output);
 
var n:integer;
 
procedure precitaj;
begin
 write('Zadaj cislo n=');
 read(n);
end;
 
function otoc(n:integer):integer;
var i,p:integer;
begin
 p:=0;
 for i:=1 to round(ln(n)/ln(10)+0.5) do begin
                         { KOMENTAR - po precitani mozes vymazat}
                         { cyklus od 1 do - pocet cifier cisla.}
                         { pocet cifier je ln(n)/ln(10)+0.5}
  p:=p*10+n mod 10;
                          { vydeli 10 a desatinu cast delenia}
                          { prida k cislu p. Tym sa cislo otoci}
  n:=trunc(n/10);
                          { vydeli 10 ale uz zaokruhli, znamena}
                          { odtrhne desatinnu cast}
  end;
 otoc:=p;
end;
 
begin
 precitaj;
 n:=otoc(n);
 write('Cislo naopak je:',n);
 readln;
end.