Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

File handling.

misj2lleunmisj2lleun Posts: 4Member
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.



[code]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]);[/code]



Comments

  • AtexAtex Posts: 268Member
    If I understood right:[code][color=Blue]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.
    [/color][/code]
  • misj2lleunmisj2lleun Posts: 4Member
    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 :(
  • AtexAtex Posts: 268Member
    : 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... ;-)
Sign In or Register to comment.