* * *

Author Topic: problems with massive on free pascal  (Read 867 times)

Legend_1

  • Newbie
  • Posts: 1
problems with massive on free pascal
« on: March 28, 2017, 08:59:27 pm »
I'm studying in liceum :), studying programming, solve the problem using arrays and loops. Recently started to study a two-dimensional array, but still don't understand how to define an individual memory cell in the array to a specific value if I use a for loop. If you can write me how to solve this problem. Thank you. :D

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5825
Re: problems with massive on free pascal
« Reply #1 on: March 28, 2017, 09:00:28 pm »
Try searching for "pascal two dimensional array"

howardpc

  • Hero Member
  • *****
  • Posts: 2399
Re: problems with massive on free pascal
« Reply #2 on: March 28, 2017, 11:01:13 pm »
Maybe this helps:

Code: Pascal  [Select]
  1. program Array2D;
  2.  
  3. const
  4.   xMin = 1;
  5.   xMax = 3;
  6.   yMin = 1;
  7.   yMax = 4;
  8.  
  9.  
  10. type
  11.   TArray = array[xMin..xMax, yMin..yMax] of integer;
  12.  
  13. var
  14.   arr: TArray;
  15.   x, y: integer;
  16.  
  17. begin
  18.   for x := xMin to xMax do
  19.     for y := yMin to yMax do
  20.       arr[x, y] := x*y;
  21.  
  22.   for x := xMin to xMax do
  23.     for y := yMin to yMax do
  24.       WriteLn('arr[',x,',',y,'] = ', arr[x, y]);
  25.  
  26.   WriteLn(#10'Press [Enter] to close');
  27.   ReadLn;
  28. end.

Kays

  • Jr. Member
  • **
  • Posts: 68
  • Whasup!?
    • KaiBurghardt.de
Re: problems with massive on free pascal
« Reply #3 on: March 29, 2017, 07:16:24 am »
Just to show that there are for … in loops and low/high functions:
Code: Pascal  [Select]
  1. program multidimarr(input, output, stderr);
  2.  
  3. {$mode objfpc}
  4.  
  5. type
  6.         firstDimension = 0..1;
  7.         secondDimension = 0..3;
  8.  
  9. var
  10.         mdarr: array[firstDimension, secondDimension] of longint;
  11.         x: firstDimension;
  12.         y: secondDimension;
  13.  
  14. begin
  15.         for x in firstDimension do
  16.         begin
  17.                 for y in secondDimension do
  18.                 begin
  19.                         mdarr[x, y] := y;
  20.                 end;
  21.         end;
  22.        
  23.         for x := low(mdarr) to high(mdarr) do
  24.         begin
  25.                 for y := low(mdarr[x]) to high(mdarr[x]) do
  26.                 begin
  27.                         writeln('mdarr[', x:3, ', ', y:3, '] = ', mdarr[x, y]);
  28.                 end;
  29.         end;
  30. end.
http://freepascal.org/docs.var the “language reference guide” is your friend.
Yours Sincerely
Kai Burghardt

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus