uses crt;
const
a = 675;
b = 865; { chisla po variantu,zdes mogut byt lubye chisla }
S = 8; { SS po variantu }
function SPlus(x1, x2: integer): integer; { sloshenie 2-x chisel v 8 SS }
var
p1, p2, rez, buf: string;
k, theend: byte;
dec, ost, code, n1, n2: integer;
begin
str(x1, p1);
str(x2, p2); { perevodim poluchennye cifry v stroki }
k := 0;
dec := 0;
rez := ''; { obnuliaem peremennye }
if p1 > p2 then
theend := length(p1)
else
theend := length(p2); { opredeliem kol-vo cifr bolshego shisla }
repeat { povtoriaem }
val(p1[length(p1) - k], n1, code);
val(p2[length(p2) - k], n2, code); { berem poislednie cifry chisel }
inc(k);
ost := (n1 + n2 + dec) mod S; { schitaem ostatok }
dec := (n1 + n2 + dec) div S; { schitaem kol-vo desitkov }
str(ost, buf); { perevodim ostatok v stroku }
rez := rez + buf; { dopisyvaem ostatok v rezultiruiuschuiu stroku }
until k > theend; { poka ne pereberem vse cifry bolshego chisla }
buf := '';
for k := length(rez) downto 1 do
buf := buf + rez[k];
{ perepivaem rezultiruiuschuiu stroku v obratnom poriadke }
val(buf, dec, code); { perevodim v chislo }
SPlus := dec; { result:=poluchennoe chislo }
end;
function DecToS(x0: integer): integer; { perevod iz 10 SS v proizvolnuiu S<11 }
var
k: byte;
x, ost, num, code: integer;
st, buf: string;
begin
x := x0;
st := '';
ost := x;
while x > 0 do { poka polozhitelnyi ostatok }
begin
ost := x mod S; { uznali ostatok }
x := x div S; { zapomnili sleduiuschee chislo }
str(ost, buf); { pereveli ostatok v stroku }
st := st + buf; { dopisali v rezultiruiuschuiu stroku }
end;
buf := '';
for k := length(st) downto 1 do
buf := buf + st[k]; { perepisali rez. stroku v obratnom poriadke }
val(buf, num, code); { pereveli v chislo }
if code = 0 then
DecToS := num { esli oshibok perevoda net, to Result:=poluchennoe chislo }
else { inache vydaem soobschenie, zavershaem programmu }
begin
clrscr;
writeln('Error: Function DecToS()!');
readkey;
halt;
end;
end;
begin
clrscr;
writeln('Variant 11');
writeln;
write('DATA: ');
writeln('a=', a, ', b=', b, ', system = ', S, ', operation = +.');
writeln;
write('STAGE 1: ');
writeln('a=', DecToS(a), ', b=', DecToS(b), ', system = ', S, '.');
write('STAGE 2: ');
writeln('a+b=', SPlus(DecToS(a), DecToS(b)), ', system = 8.');
write('STAGE 3: ');
writeln('c=a+b; c=', a + b, ', system = 10;', ' c=', DecToS(a + b),
', system = ', S, '.');
write('STAGE 4: ');
if SPlus(DecToS(a), DecToS(b)) = DecToS(a + b) then
writeln('Good!')
else
writeln('Bad!');
writeln;
write('Press any key to Exit...');
readkey;
end.