1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
program final;
{$APPTYPE CONSOLE}
uses
sysutils;
var
nbch,i,basedep,basefin:integer;
ch,rep:string;
erreur,controlsaisie:boolean;
function control (nb:string;basedep:integer):boolean;
begin
nbch:=length(nb);
i:=1;
erreur:= false;
while (not erreur) and (i <= nbch) do
begin
ch:= copy(nb,i,1);
if (ch > '0 ')and (ch <'basedep-1')
then erreur:= true ;
end;
end;
function conver (basefin:integer;nb:string):string;
begin
quotient := nb div basefin
reste := quotient mod basefin
result:= result + intostr(result)
end;
begin
write('voulez-vous effectuer une conversion ? o/n:');
readln(rep);
while rep = 'o' do
begin
write('saisir un nombre:');
readln(nb);
write ('base de depart:');
readln(basedep);
write ('base de fin:');
readln(basefin);
controlsaisie:= control (nb,basedep);
if controsaisie:= true
then writeln('erreur saisie')
else resultat:= conver(basefin,nb);
write('resultat:',resultat);
write('voulez-vous effectuer une autre conversion ? o/n:');
readln(rep);
end;
end. |
Partager