Salut Dadar; voici le programme:
Program Somme_binaire;
Uses crt;
Label 1,2,3;
Type Tab=array[1..100] of integer;
Var T:Tab;
A,B,C,i,n,Somme,rep: integer;
Function nbpos(X:integer):integer;
begin
n:=0;
While X<>0 do
begin
X:=X div 10;
n:=n+1;
end;
nbpos:=n;
end;
Function Puiss(b,e:integer):integer;
begin
n:=1;
If e<0 then Puiss:=1
Else
begin
For i:=1 to abs(e) do n:=n*b;
if n>=0 then Puiss:=n
else Puiss:=1 div n;
end;
end;
Function Verif(X:integer):boolean;
var bin:boolean;
begin
bin:=false;
While X<>0 do
begin
n:=X mod 10;
X:=X div 10;
if (n<>0) and (n<>1) then bin:=false
else bin:=true;
end;
Verif:=bin;
end;
Begin
1:Clrscr;
Textcolor(2);
Writeln('** Ce programme additionne 2 nombres binaires **');
writeln;writeln;
Writeln('Donnez les 2 nombres binaires:');
Write('A = '); readln(A);
Write('B = '); readln(B);
Writeln;
If (Verif(A)) or (Verif(B))=False then
begin
Textcolor(4+blink);
Writeln('Erreur! Les nombres ne sont pas en binaire');
Writeln;
Writeln('Tapez n''importe qu''elle touche');
Writeln;
readkey;
Goto 1;
end;
Somme:=A+B;
C:=Somme;
n:=nbpos(Somme);
For i:=1 to n+1 do T[i]:=0;
For i:=1 to n+1 do
begin
T[i]:=C mod 10;
C:=C div 10;
end;
For i:=1 to n+1 do
begin
if T[i]=2 then
begin
T[i]:=0; T[i+1]:=T[i+1]+1;
end
else
begin if T[i]=3 then
begin
T[i]:=1;T[i+1]:=T[i+1]+1;
end;
end;
end;
C:=T[1];
For i:=2 to n+1 do C:=C+(T[i]*Puiss(10,i-1));
writeln;
Writeln('',A,' + ',B,' = ',C);
Writeln;
3:Textcolor(2);
Writeln('Un autre calcul --------- Tapez 1');
Writeln('Quitter ----------------- Tapez 2');
readln(rep);
if (rep<>1) and (rep<>2) then
begin
Textcolor(4+blink);
Writeln('Reponse insignifiante!');
Writeln;
Writeln('Tapez n''importe qu''elle touche');
Writeln;
Readkey;
Goto 3;
end;
Case rep of
1:Goto 1;
2:Goto 2;
end;
2:Writeln('** Merci d''avoir execute ce programme **');
readln;
End.
j'espere que ça marche pour toi,
autres questions: rosella001@yahoo.fr