asmodeus94

rozkladNaCzynnikiPierwsze

May 17th, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.33 KB | None | 0 0
  1. program rozklad;
  2. uses crt;
  3. const
  4. n = 2000;
  5. var
  6. tabC : array [1..n] of longint;
  7. tabIter,codeBl : integer;
  8. a,kL : longint;
  9. ok,zle : byte;
  10. wybor,l : string;
  11. label zlaLiczba,zeroLubJeden;
  12. begin
  13. wybor:='1';
  14. REPEAT
  15.    zlaLiczba:
  16.    clrscr;
  17.    write('Podaj liczbe: ');readln(l);
  18.    val(l,kL,codeBl);
  19.    if(codeBl<>0) then begin clrscr;goto zlaLiczba;end;
  20.    write('Rozklad ',l,' na czynniki: ');
  21.    if l='1' then write('1');
  22.    if l='0' then write('0');
  23.    if (l='0') OR (l='1') then goto zeroLubJeden;
  24.    tabIter:=0;
  25.    REPEAT
  26.       a:=2;
  27.       ok:=0;
  28.       zle:=0;
  29.       REPEAT
  30.       if zle=1 then begin
  31.          a:=a+1;
  32.          zle:=0;
  33.       end;
  34.       if (kL mod a = 0) then begin
  35.          inc(tabIter);
  36.          tabC[tabIter]:=a;
  37.          kL:=kL div a;
  38.          ok:=1;
  39.       end ELSE zle:=1;
  40.       UNTIL (ok=1) OR (a=kL);
  41.    UNTIL kL=1;
  42.    if sizeof(tabC)>0 then begin
  43.       for a:=1 to n do begin
  44.          if tabC[a]=0 then continue;
  45.          write(tabC[a]);
  46.          if tabC[a+1]<>0 then write(', ');
  47.          tabC[a]:=0;
  48.       end;
  49.    end;
  50.    zeroLubJeden:
  51.    writeln;
  52.    write('Nacisnij dowolny klawisz');
  53.    readkey;clrscr;
  54.    writeln('1 - rozloz inna liczbe na czynniki');
  55.    writeln('2 - zakoncz');
  56.    write('Podaj: ');REPEAT readln(wybor);UNTIL (wybor[1]='1') OR (wybor[1]='2');
  57. UNTIL wybor='2';
  58. end.
Advertisement
Add Comment
Please, Sign In to add comment