Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4098
Number of posts: 14002

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

Report
array and diagonal Posted by aloku on 20 Apr 2003 at 7:08 AM
Hello! I have two dimensional array - 6 rows,6 columns. I need to switch the biggest number (which is over the main diagonal) with the least number (which is under the main diagonal). It looks like this:

1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
25 26 27 28 29 30
31 32 33 34 35 36

so, i need to switch 30 with 7. Any ideas?
Report
Re: array and diagonal Posted by zibadian on 20 Apr 2003 at 8:43 AM
: Hello! I have two dimensional array - 6 rows,6 columns. I need to switch the biggest number (which is over the main diagonal) with the least number (which is under the main diagonal). It looks like this:
:
: 1 2 3 4 5 6
: 7 8 9 10 11 12
: 13 14 15 16 17 18
: 19 20 21 22 23 24
: 25 26 27 28 29 30
: 31 32 33 34 35 36
:
: so, i need to switch 30 with 7. Any ideas?
:
First you'll have to find the location of those numbers. This involves two for-do loops and an if-then. Here is an untested example of finding the biggest number above the main dia.:
var
  BigX, BigY, X, Y: integer;
begin
  BigX := 2; { start with the top-left most number as begin value for the max: 2 in the example }
  BigY := 1;
  for Y := 1 to 6 do 
    for X := Y to 6 do begin { iterate through top-right half, inc. main dia. }
      if (X <> Y) then begin { Remove main dia. }
        if Numbers[X, Y] > Numbers[BigX, BigY] then begin
          BigX := X; { Check for a larger number }
          BigY := Y;
        end;
      end;
    end;
end;

A similar code can be constructed for the smallest number below the diagonal. Switching the numbers shouldn't be too difficult, but here is the code anyway:
  Temp := Numbers[BigX, BigY];
  Numbers[BigX, BigY] := Numbers[SmallX, SmallY];
  Numbers[SmallX, SmallY] := Temp;

Report
Re: array and diagonal Posted by Misscherysa on 12 Mar 2013 at 3:57 PM
Please help
Attachment: Diogonal matrix 10.rar (10979 Bytes | downloaded 15 times)
Report
Re: array and diagonal Posted by Misscherysa on 12 Mar 2013 at 3:59 PM
Please help
Attachment: Diogonal matrix 10.rar (10979 Bytes | downloaded 15 times)
Report
Re: array and diagonal Posted by Misscherysa on 12 Mar 2013 at 4:00 PM
Please help
Attachment: Diogonal matrix 10.rar (10979 Bytes | downloaded 15 times)
Report
Re: array and diagonal Posted by Misscherysa on 12 Mar 2013 at 4:03 PM
PLEASE HELP if there is something that you dont understand my email Covergirl.Daina@gmail.com
Attachment: Diogonal matrix 10.rar (10979 Bytes | downloaded 13 times)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.