Advertisement
niepok

z10naDowolny

Jan 25th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.56 KB | None | 0 0
  1. program konwerter2;
  2. var
  3.    a, b, c, d, i, x, e, q : integer;
  4.    g : char;
  5.    tab1 : array [1..100] of integer; //wynik w systemach 2-10
  6.    tab2 : array [1..100] of char;    //wynik w systemach 11-16
  7.    tab3 : array [1..100] of char;    //liczba w systemie 11-16
  8.  
  9.  
  10. Procedure z10naDowolny;     {konwersja liczby z systemu dziesiętnego na dowolny z zakresu 2-16}
  11. begin
  12.   Write('Podaj liczbe w systemie 10: ');
  13.   readln(a);
  14.   Write('Podaj podstawe systemu, na ktory chcesz zamienic liczbe(od 2 do 16): ');
  15.   readln(b);
  16.   c:=a;
  17.   i:=1;
  18.   Case b of
  19.       2..10 : begin { Z dziesiętnego na 2 do 10 }
  20.                    Repeat
  21.                          d := c mod b;
  22.                          tab1[i]:=d;
  23.                          e := c div b;
  24.                          i:=i+1;
  25.                          c := e;
  26.                    until c<=0
  27.                end;
  28.       11..16 : begin    {11-16}
  29.                    Repeat
  30.                          d := c mod b;
  31.                                       Case d of
  32.                                           0: g:='0';
  33.                                           1: g:='1';
  34.                                           2: g:='2';
  35.                                           4: g:='4';
  36.                                           5: g:='5';
  37.                                           6: g:='6';
  38.                                           7: g:='7';
  39.                                           8: g:='8';
  40.                                           9: g:='9';
  41.                                           10: g:='A';
  42.                                           11: g:='B';
  43.                                           12: g:='C';
  44.                                           13: g:='D';
  45.                                           14: g:='E';
  46.                                           15: g:='F';
  47.                                       end;
  48.                                       tab2[i]:=g;
  49.                          e := c div b;
  50.                          i:=i+1;
  51.                          c := e;
  52.                    until c<=0
  53.              end;
  54.       end;
  55.   write('Liczba ',a,' w systemie o podstawie ',b,' to: ');
  56.   i:=i-1;
  57.   Case b of
  58.       2..10 : begin
  59.               For x:=i downto 1 do
  60.                   begin
  61.                   write(tab1[i]);
  62.                   i:=i-1;
  63.                   end;
  64.                end;
  65.       11..16 : begin
  66.                For x:=i downto 1 do
  67.                    begin
  68.                    write(tab2[i]);
  69.                    i:=i-1;
  70.                    end;
  71.                end;
  72.       end;
  73. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement