//Ввод файла в текстовом редакторе Var f:text; s:string; a:integer; begin writeln('First file:'); assign(f,'text.txt'); reset(f); while not Eof(f) do begin read(f,a); write(a:4); if (a>8) or (a<6) then a:=sqr(a); s:=s+a+' '; end; close(f); writeln; writeln('Final file:'); write(s); assign(f,'text.txt'); rewrite(f); write(f,s); close(f); end.
Пример работы программы: First file: 1 2 3 4 5 6 7 8 Final file: 1 4 9 16 25 6 7 8
//Ввод файла программе
Var f:text; s,s1:string; a,i:integer; begin assign(f,'text.txt'); rewrite(f); for i:=1 to 10 do begin read(a); write(f,a); s1:=s1+inttostr(a)+' '; if (a>8) or (a<6) then a:=sqr(a); s:=s+inttostr(a)+' '; end; close(f); writeln('First file:'); writeln(s1); writeln('Final file:'); write(s); assign(f,'text.txt'); rewrite(f); write(f,s); close(f); end.
Пример ввода: 1 2 3 4 5 6 7 8 9 10 Пример вывода: First file: 1 2 3 4 5 6 7 8 9 10 Final file: 1 4 9 16 25 6 7 8 81 100
Объяснение:
var x,i:integer;
begin
for i:=1 to 50 do
x:=x+i;
write(x);
end.