Multidimension arrays 
Author Message
 Multidimension arrays

Quote:

> I want to create a multiplication table for the values 1-9, To do this I
> propose to use a 2 dimensional array [1-9,1-9].
> then I propose to create another array is created for the result. eg 4 * 7 =
> 28
> Then  I need to separarate the two digits of 28 into 2 and 8 (how to do
> this?). and put them into separate arrays again.
> But if I do this for all the digits 1-9 would result in a 2 * 9 * 9 array.
> This would be huge.

> Am I thinking along the right track or could it be done easier?

Hi

   To the second question, I have no answer.  To the first, use 'num div 10' to obtain the tens digit, and 'num mod ten' to obtain the ones
digit.

Daniel Morton



Wed, 18 Jun 1902 08:00:00 GMT  
 Multidimension arrays
I want to create a multiplication table for the values 1-9, To do this I
propose to use a 2 dimensional array [1-9,1-9].
then I propose to create another array is created for the result. eg 4 * 7 =
28
Then  I need to separarate the two digits of 28 into 2 and 8 (how to do
this?). and put them into separate arrays again.
But if I do this for all the digits 1-9 would result in a 2 * 9 * 9 array.
This would be huge.

Am I thinking along the right track or could it be done easier?



Wed, 18 Jun 1902 08:00:00 GMT  
 Multidimension arrays

Quote:



>> I want to create a multiplication table for the values 1-9, To do this I
>> propose to use a 2 dimensional array [1-9,1-9].
>> then I propose to create another array is created for the result. eg 4 *
7 =
>> 28
>> Then  I need to separarate the two digits of 28 into 2 and 8 (how to do
>> this?). and put them into separate arrays again.
>> But if I do this for all the digits 1-9 would result in a 2 * 9 * 9
array.
>> This would be huge.

>> Am I thinking along the right track or could it be done easier?

>Hi

>   To the second question, I have no answer.  To the first, use 'num div

10' to obtain the tens digit, and 'num mod ten' to obtain the ones digit.

Quote:

>Daniel Morton

Here is an answer in pseudo-code:

Have a fully populated 9x9 integer array for "tens", using Daniel Morton's
approach
Have a fully populated 9x9 integer array for "ones", again using Daniel
Morton's approach
GetUserInput(x)
GetUserInput(y);
Write tens[x,y] ones[x,y] to the screen

Example for 4*9=36:

tens[4,9] := 3;
ones[4,9] := 6;
writeln(tens[4,9], ones[4,9]);

KlausL



Wed, 18 Jun 1902 08:00:00 GMT  
 Multidimension arrays

Quote:

>I want to create a multiplication table for the values 1-9, To do this I
>propose to use a 2 dimensional array [1-9,1-9].
>then I propose to create another array is created for the result. eg 4 * 7
=
>28
>Then  I need to separarate the two digits of 28 into 2 and 8 (how to do
>this?). and put them into separate arrays again.
>But if I do this for all the digits 1-9 would result in a 2 * 9 * 9 array.
>This would be huge.

>Am I thinking along the right track or could it be done easier?

If I'm understanding correctly you want to create a "multiplication table"
for values 1 to 9.
Which mean you like to be able to look up any multiplication from 1*1 to
9*9?
And then you like to split the digits.

Why not just do the following.

var
 table:array[1..9,1..9,1..2] of byte;
 i,j:integer;

begin
for j := 1 to 9 do
 for i := 1 to 9 do
  begin
    table[i,,j,1] := (i*j)mod 10;
    table[i,,j,2] := (i*j)div 10;
  end;

And by the way 2*9*9 isn't to big by a long shot!

You can have up to about 60000 bytes in an array.

Chaou
Heinrich

Check my web-site:
http://homes.arealcity.com/Heinrichshomepage/
Includes a complete TP tutoriul and more!



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Array of Array

2. move INTERBASE ARRAY to DELPHI ARRAY ?

3. lgarray0.zip TP unit for huge arrays and arrays of sorted strings

4. floating point arrays and C arrays - HELP ME

5. Help! array of type array

6. Resizing arrays and multi-dimentional arrays of *ALL* types...

7. Is an "array of arrays" possible?

8. Remove items from array w/o making another array?

9. FIBPlus, Interbase and array fields

10. save mutiple writeln's into an array

11. Add and delete items from arrays

12. problem passing array values.

 

 
Powered by phpBB® Forum Software