Advertisement
Guest User

David J Code Source (Classifié)

a guest
Oct 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.88 KB | None | 0 0
  1. program BinairOuPas;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils,ShellAPI;
  7. function bintodec(b,k:longint):integer;
  8.  begin { breakpoint condition}
  9.   if b=0 then
  10.     bintodec:=0
  11.   else
  12.     bintodec:=bintodec(b div 10, k*2)+b mod 10 * k; {recursive call}
  13. end;
  14.  
  15. var
  16.   choix : string;
  17.   a,b,d,e,f:integer;
  18.   c:array[1..255] of integer;
  19. begin
  20.   { TODO -oUser -cConsole Main : placez le code ici }
  21.     Writeln('------------------------------------------');
  22.     Writeln('     Convertiseur binaire by David      ');
  23.     Writeln('------------------------------------------');
  24.     Writeln('Bonjour, voici les choix disponnibles :');
  25.     Writeln('1. Convertir de decimal en binaire');
  26.     Writeln('2. Convertir de binaire en decimal');
  27.     Writeln;
  28.     Write('Votre choix : ');
  29.     Readln(choix);
  30.   if choix = '1' then
  31.   begin
  32.     Writeln;
  33.     Writeln('Vous avez choisis la conversion binaire, veuillez indiquer votre nombre');
  34.     Write('Votre nombre : ');
  35.     Readln(a);
  36.   if a<=1 then write(a) else
  37.   repeat
  38.     b:=b+1;
  39.     d:=trunc(a/2);
  40.     c[b]:=a mod 2;
  41.   if d<=1 then
  42.   begin
  43.     b:=b+1;
  44.     c[b]:=d;
  45.   end;
  46.     a:=d;
  47.   until d<=1;
  48.  
  49.   for e:=b downto 1 do
  50.   begin
  51.     write(c[e]);
  52.   end;
  53.     Writeln;
  54.     Writeln('Appuyer sur une touche pour continuer');
  55.     Readln
  56.   {Fonction de conversion de decimal en binaire}
  57.   end
  58.   else if choix = '2' then
  59.   begin
  60.     Writeln('Vous avez choisis la conversion decimal, veuillez indiquer votre nombre');
  61.     Write('Votre nombre : ');
  62.     Readln(b);
  63.     write;
  64.     write('Votre nombre converti : ');
  65.     writeln(bintodec(b,1)); {Appel de la fonction de covnersion}
  66.   {Fonction de conversion de binaire en decimal}
  67.     writeln('Appuyer une touche pour continuer');
  68.     Readln;
  69.  
  70.   end
  71.   else
  72.   begin
  73.    Writeln('Vous n''avez pas indiquer de chiffre, appuyer sur une touche pour fermer l''application');
  74.    Readln;
  75.   end
  76. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement