Advertisement
eggggggggor

DigitsSort

Apr 27th, 2024
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.16 KB | None | 0 0
  1. program DigitsSort;
  2.  
  3. const
  4.     N = 100;
  5.  
  6. function randomInRange(n, m: integer): integer;
  7. begin
  8.     randomInRange := Random(m - n + 1) + n;
  9. end;
  10.  
  11. var
  12.     arr: array[1..N] of integer;
  13.     single_digits: array[1..N] of integer;
  14.     double_digits: array[1..N] of integer;
  15.     singles_counter, doubles_counter, i: integer;
  16.  
  17. begin
  18.     singles_counter := 0;
  19.     doubles_counter := 0;
  20.  
  21.     for i := 1 to N do
  22.     begin
  23.         arr[i] := randomInRange(0, 25);
  24.         Write(arr[i], ' ');
  25.     end;
  26.     WriteLn;
  27.  
  28.     for i := 1 to N do
  29.     begin
  30.         if (arr[i] >= 0) and (arr[i] < 10) then
  31.         begin
  32.             singles_counter := singles_counter + 1;
  33.             single_digits[singles_counter] := arr[i];
  34.         end
  35.         else
  36.         begin
  37.             doubles_counter := doubles_counter + 1;
  38.             double_digits[doubles_counter] := arr[i];
  39.         end;
  40.     end;
  41.  
  42.     for i := 1 to doubles_counter do
  43.     begin
  44.         singles_counter := singles_counter + 1;
  45.         single_digits[singles_counter] := double_digits[i];
  46.     end;
  47.  
  48.     for i := 1 to N do
  49.     begin
  50.         Write(single_digits[i], ' ');
  51.     end;
  52.     WriteLn;
  53. end.
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement