GamerSK

zoradenie

Apr 6th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.25 KB | None | 0 0
  1. program operaciesosubormi;
  2. {$APPTYPE CONSOLE}
  3. uses SysUtils;
  4. var r,u:text;
  5.     n,x,i,max,min,s,pc,udaj,pom:byte;
  6.     c:array[1..255] of byte;
  7. begin
  8.   { TODO -oUser -cConsole Main : Insert code here }
  9.   assign(r,'randomcisla.txt'); assign(u,'usporiadanecisla.txt');
  10.   write('Kolko cisiel chcete vygenerovat?: ');
  11.   readln(n);
  12.   write('Zadajte rozsah cisiel (0-x): ');
  13.   readln(x);
  14.   append(r);
  15.   randomize;
  16.   for i:=1 to n do
  17.     begin
  18.       c[i]:=random(x);
  19.       writeln(r,c[i]);
  20.     end;
  21.   writeln(r);
  22.   close(r);
  23.   reset(r); append(u);
  24.   max:=0;
  25.   s:=0;
  26.   pc:=0;
  27.   min:=255;
  28.   while not eof(r) do
  29.     begin
  30.       readln(r,udaj);
  31.       write(udaj,' ');
  32.       s:=s+udaj;
  33.       pc:=pc+1;
  34.       if udaj>max then max:=udaj;
  35.       if udaj<min then min:=udaj;
  36.     end;
  37.   writeln;
  38.   writeln('Priemer cisiel: ',s/pc:0:2);
  39.   writeln('Maximalne cislo: ',max);
  40.   writeln('Minimalne cislo: ',min);
  41.   close(r); close(u);
  42.   i:=0;
  43.   while i<>n do
  44.     begin
  45.       inc(i);
  46.       if c[i]>c[i+1] then
  47.         begin
  48.           pom:=c[i];
  49.           c[i]:=c[i+1];
  50.           c[i+1]:=pom;
  51.           i:=0;
  52.         end;
  53.     end;
  54.   append(u);
  55.   for i:=1 to n do
  56.     begin
  57.       writeln(u,c[i]);
  58.     end;
  59.   writeln(u);
  60.   close(u);
  61.   readln;
  62. end.
Advertisement
Add Comment
Please, Sign In to add comment