Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
File handling. Posted by misj2lleun on 31 Jan 2010 at 12:46 PM
I'm beginner and i need to do that program :

File (input.txt) have three rows and each row has exactly three integers(I need to ask user to enter integers). Establish a program that reads in integers and writes them in reverse order (i need to exchange rows and columns to ) in file output.txt.

Like. If i have numbers :

14 67 34 17 2 89
29 45 32 then ===> 32 45 29
89 2 17 34 67 14

I've done something but i think it's 100% wrong...I've been struggling with that some weeks and i don't know what to do.



Program kt6_2;


var
   row1 : array[1..3] of integer;
   row2 : array[1..3] of integer;
   row3 : array[1..3] of integer;

Begin
   writeln('Enter first row:');
   readln(row1[3]);
   writeln('Enter second row:');
   readln(row[3]);
   writeln('Enter third row:');
   readln(row3[3]);




Report
Re: File handling. Posted by Atex on 31 Jan 2010 at 10:41 PM
If I understood right:
var t:array[1..3,1..3] of integer;
    i,j:byte;
    f:text;

begin
 for i:=1 to 3 do
  for j:=1 to 3 do
   begin write('Enter element [',i,',',j,']  ');readln(t[i,j]);end;
 assign(f,'input.txt');
 rewrite(f);
 for i:=1 to 3 do begin
  for j:=3 downto 1 do
   write(f,t[i,j],' ');
  writeln(f);
 end;
 close(f);
end.

Report
Re: File handling. Posted by misj2lleun on 1 Feb 2010 at 8:36 AM
It's working but i need to change last row to first row. I tried something but nothing isn't working. When i changed i and j then my 'input.txt' showed me nothing :(
Report
Re: File handling. Posted by Atex on 1 Feb 2010 at 2:25 PM
: It's working but i need to change last row to first row. I tried
: something but nothing isn't working. When i changed i and j then my
: 'input.txt' showed me nothing :(
:

Observe what I did to reverse the columns, reversing the rows could be done the same way...



 

Recent Jobs