Advertisement
Domerk

Типизированные файлы 3

Oct 20th, 2011
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.10 KB | None | 0 0
  1. {Генерирует числа, находит наибольшее и наименьшее, удаляет последнее. К сожалению, всё.}
  2.  
  3. program tip;
  4. uses crt;
  5.  
  6. var
  7. f: file of integer;
  8. a1, n, i, amax, nmax, na, amin, nmin : integer;
  9. begin
  10. clrscr;
  11.  
  12. writeln ('Vvod kolichestva chisel');
  13. readln (n);
  14. assign (f, 'file.int');
  15. rewrite (f);
  16. randomize;
  17.  
  18. for i := 1 to n do begin
  19. a1:=Random (100);
  20. write (f, a1);
  21. end;
  22.  
  23. reset (f);
  24. clrscr;
  25.  
  26. for i :=1 to n do begin
  27. read (f, a1);
  28. writeln (a1);
  29. end;
  30.  
  31. reset (f);
  32. amax:=-1;
  33. amin:=101;
  34.  
  35. while not eof(f) do begin
  36. read (f, a1);
  37.     if a1 > amax then begin
  38.     amax:=a1;
  39.     nmax:=filepos (f);
  40.     end;
  41.     if a1<amin then begin
  42.     amin:=a1;
  43.     nmin:=filepos (f);
  44.     end; end;
  45.  
  46. writeln ('max = ', amax, ' nmax = ', nmax);
  47. writeln ('min = ', amin, ' nmin = ', nmin);
  48.  
  49. seek (f, nmax-1);
  50. read (f, a1);
  51. seek (f, n);
  52. write (f, a1);
  53.  
  54. i:=n+1;
  55. na:=nmax;
  56.  
  57. reset (f);
  58.  
  59. seek (f, n-1);
  60. truncate (f);
  61.  
  62. reset (f);
  63. while not eof(f) do begin
  64. read (f, a1);
  65. writeln (a1);
  66. end;
  67.  
  68. close (f);
  69. readln;
  70. clrscr;
  71. end.
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement