Generate Pascal code text file

2

I have a pascal code. It is as follows:

Program Pzim ;
   var
     i:integer;
     vect:array[1..1001] of integer;
Begin
     i:=1;
     for i:= 1 to 999 do
     vect[i]:=i+1;
     for i:= 1 to 999 do
     writeln (vect[i]);
   readln;
End.

The code in Pascalzim prints a sequence of numbers on the screen. I wanted to save in text file whatever is generated by the code.

Would it be possible using the same pascal, or who knows otherwise, using notepad ++ for example?

    
asked by anonymous 13.02.2016 / 22:46

2 answers

3

I found out! my question was answered in the StackOverflow

The code looks like this:

Program Pascal ;

var
  i:integer;
  vect:array[1..1001] of integer;
  Myfile: text;

begin
  i:=1;
  for i:= 1 to 999 do
    vect[i]:=i+1;

  Assign(Myfile, 'Myfile.txt');
  Rewrite(MyFile);

  for i:= 1 to 999 do
  begin
    WriteLn (vect[i]);
    WriteLn(Myfile, vect[i]);
  end;
  Close(Myfile);
  ReadLn;
end.
    
14.02.2016 / 00:44
2

A small improvement that brings learning to the organization of the impression of the result.

Program Pascal ;

var
  i, j:integer;
  vect:array[1..1000] of integer;
  Myfile: text;

begin
  j := 0;
  for i := 1 to 1000 do
  begin
    vect[i] := j + 1;
        j := j + 1;
  end;

  Assign(Myfile, 'Myfile.txt');
  Rewrite(MyFile);

  for i := 1 to 1000 do
  begin
    if i < 1000 then
        begin   
        Write(vect[i], ', ');
        Write(Myfile, vect[i], ', ');
    end else begin
        Write(vect[i], '. ');
        Write(Myfile, vect[i], '.');
    end;
  end;

  Close(Myfile);
  ReadLn;
end.
    
25.03.2016 / 17:00