Program sujet1;
Uses crt;
Type
base = Record
bin : string[20];
oct : string[20];
hex : string[20];
End;
fnombre = file Of word;
fbase = file Of base;
//*****************************************
Var
n : integer;
f : fnombre;
fb : fbase;
//*****************************************
Function conv_bin(dec:word) : string;
Var
r : word;
ch_bin,chr : string[20];
Begin
ch_bin := '';
Repeat
r := dec Mod 2;
str(r,chr);
ch_bin := chr+ch_bin;
dec := dec Div 2
Until (dec =0);
conv_bin := ch_bin;
End;
//*****************************************
Function conv_oct(dec:word) : string;
Var
r : word;
ch_oct,chr : string[20];
Begin
ch_oct := '';
Repeat
r := dec Mod 8;
str(r,chr);
ch_oct := chr+ch_oct;
dec := dec Div 8
Until (dec =0);
conv_oct := ch_oct;
End;
//*****************************************
Function conv_hex(dec:word) : string;
Var
r : word;
ch_hex,ch_r : string[20];
Begin
ch_hex := '';
Repeat
r := dec Mod 16;
If (r<10) Then
Begin
str(r,ch_r);
ch_hex := ch_r+ch_hex;
End
Else
Begin
r := r+(ord('A')-10);
ch_hex := chr(r)+ch_hex;
End;
dec := dec Div 16
Until (dec =0);
conv_hex := ch_hex;
End;
//*****************************************
Procedure creation(Var f:fnombre; n:integer);
Var
m,i : word;
Begin
assign(f,'c:\bac2008\nombres.dat');
rewrite(f);
For i:=1 To n Do
Begin
Repeat
write('saisir un entier inférieur à < 32000: ');
readln(m);
Until (m<32000);
write(f,m);
End;
close(f);
End;
//*****************************************
Procedure affiche(Var f:fnombre;Var fb:fbase;n:integer);
Var
i : integer;
dec : word;
b : base;
Begin
reset(f);
assign(fb,'c:\bac2008\nbr_conv.dat');
rewrite(fb);
For i:=1 To n Do
Begin
read(f,dec);
With b Do
Begin
bin := conv_bin(dec);
oct := conv_oct(dec);
hex := conv_hex(dec);
End;
With b Do
Begin
write('conversion du (',dec,')10 est: (');
write( bin,')2, (',oct,')8 et (',hex,')16');
writeln;
write(fb,b);
End;
End;
close(fb);
close(f);
End;
//*****************************************
Begin
Repeat
write('Saisir le nombre des nombres décimaux: ');
readln(n);
Until (n In[5..50]);
creation(f,n);
clrscr;
writeln('----------------------------------------------------------');
writeln('-- Liste des nombres décimaux ainsi que leurs conversion--');
writeln('----------------------------------------------------------');
affiche(f,fb,n);
End.
Inscription à :
Publier les commentaires (Atom)