AboutAlex Barry Expertise I have been a qbasic programmer since 2000, creating games, minor libraries and various small programs. I have experience using interrupts, graphics, file input/output, the mouse cursor, and using libraries. I have also learned FreeBASIC, c/c++, python, php and html.
I do not claim to be an absolute authority in any language, but I don't mind looking things up and learning with you.
Experience Hobby programming since 2000
I no longer belong to any community programming groups, but do have knowledge of *basic dialects and C/C++
I have a program to do. We get 2 numbers to input. Lets say the numbers are 4 and 5. The product of these 2 numbers is 20.
We need to make a spiral thing or whatever that goes from 1 to 20. It should look like this.
To be honest, I've never done a program to do this, but I'll see what I can do to help you out.
First, you'll need (at least) 6 variables:
DIM first AS INTEGER
DIM second AS INTEGER
REDIM matrix(0, 0) AS INTEGER
DIM size AS INTEGER
DIM x AS INTEGER
DIM y AS INTEGER
Now, to get the input,
INPUT "First number : ", first
INPUT "Second number : ", second
' Resize the matrix
size = first * second
IF size MOD 2 <> 0 THEN
x = FLOOR( size / 2 )
y = size - x
ELSE
x = size / 2
y = x
END IF
REDIM matrix( 1 TO x, 1 TO y ) AS INTEGER
' Create a spiral with the numbers
FOR y = 1 TO UBOUND( matrix, 2 )
FOR x = 1 TO UBOUND( matrix, 1 )
' The comma at the end keeps it on the same line
PRINT matrix( x, y ),
NEXT x
' This print statement moves the cursor to the beginning of the next line
PRINT
NEXT y
Now, to do a spiral, I think I have a way of doing it, but I will let you try before I give you an answer for that. One thing to remember is that in a spiral, when you hit a spot that already has a number, or it's the edge of the array, there is only one constant direction it can turn (for instance, in an entire spiral, there could only be a left hand turn [counter-clockwise]).
I hope that helps, and take care,
-Alex
PS: If you have trouble making the spiral, just ask a followup question about it, and I'll give you my algorithm.