Sawy3R11

Z1

Jan 18th, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.39 KB | None | 0 0
  1. program project1;
  2.  
  3. var
  4.   tablica : array [0..7] of integer;
  5.   i, i2 : integer;
  6.   plik : TextFile;
  7.  
  8. function srednia(tablica : array of integer) : double;
  9. begin
  10.     srednia :=0;
  11.     i2:=0;
  12.     for i:=0 to 7 do
  13.         if (tablica[i] mod 2) = 0 then
  14.         begin
  15.         srednia := srednia + tablica[i];
  16.         i2:=i2+1;
  17.         end;
  18.     srednia := srednia/i2;
  19. end;
  20. procedure zblizona(tablica : array of integer);
  21. var
  22.   pomoc, min, max :integer;
  23.  
  24. begin
  25.      min := tablica[0];
  26.      max := tablica[0];
  27.      pomoc := round(srednia(tablica));
  28.  
  29.      for i:=0 to 7 do
  30.      begin
  31.        if (tablica[i] < min) then min := tablica[i];
  32.        if (tablica[i] > max) then max := tablica[i];
  33.      end;
  34.  
  35.      for i:=0 to 7 do
  36.      begin
  37.        if  ((tablica[i] >=min) and  (tablica[i] <pomoc)) then min :=tablica[i];
  38.        if ((tablica[i] <= max) and (tablica[i] > pomoc )) then max := tablica[i];
  39.      end;
  40.      if (max-pomoc) > (pomoc-min) then writeln(#10#13,'Najblizsz: ', min)
  41.      else writeln(#10#13,'Najblizsza: ', max);
  42. end;
  43. begin
  44.   for i:=0 to 7 do
  45.       readln(tablica[i]);
  46.   for i:=0 to 7 do
  47.       writeln(#10#13,'[',i,']', tablica[i]);
  48.   writeln('Srednia: ', srednia(tablica));
  49.  
  50.   zblizona(tablica);
  51.  
  52.   AssignFile(plik, 'nowy1.txt');
  53.   Rewrite(plik);
  54.  
  55.   for i:=0 to 7 do
  56.       writeln(plik, tablica[i],#10#13,#10#13);
  57.  
  58.   CloseFile(plik);
  59.  
  60.  
  61.   readln();
  62. end.
Add Comment
Please, Sign In to add comment