mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2004-09-14, 06:11   #1
rn0dal
 
Sep 2004

416 Posts
Default Ubasic Array question

How do I store all the numbers from 0 to 1000,in an array?thanks a lot for your time.

Last fiddled with by rn0dal on 2004-09-14 at 06:12
rn0dal is offline   Reply With Quote
Old 2004-09-14, 08:34   #2
jocelynl
 
Sep 2002

10616 Posts
Default

Quote:
Originally Posted by rn0dal
How do I store all the numbers from 0 to 1000,in an array?thanks a lot for your time.
Dim a(1000)
for x=0 to 1000
a(x)=x
next


use the help starter to get help
ubh.bat

Joss

Last fiddled with by jocelynl on 2004-09-14 at 08:35
jocelynl is offline   Reply With Quote
Old 2004-09-14, 14:57   #3
rn0dal
 
Sep 2004

22 Posts
Default

Thanks a lot for your help,now one more question,lets say I want that array to be, (the number the user enters) - 2.How would I do that?


could it be like this?


10 input "Last Number";x
20 p=0
30 Dim m(x-2)
40 For I = 2 to x
50 m(p) = I
60 p = p + 1
70 next I


the reason why i aked it becuase I did not find an example about it.

Last fiddled with by rn0dal on 2004-09-14 at 14:58
rn0dal is offline   Reply With Quote
Old 2004-09-14, 20:13   #4
Uncwilly
6809 > 6502
 
Uncwilly's Avatar
 
"""""""""""""""""""
Aug 2003
101×103 Posts

3×7×19×23 Posts
Default

You should be able to eliminate p.
Assuming you want x-2 elements and each element m(z) to be equal to z+2, try this:

Code:
10 input "Last Number";x
30 Dim m(x-2)
40 For i = 2 to x
50 m(i-2) = i
70 next i
m(0)=2
m(1)=3
......
m(x)=x+2


My arrays are a bit rusty, but each extra step you get rid of (and counters that are doing the same steping, like p & i), speeds things along.
Uncwilly is offline   Reply With Quote
Old 2004-09-14, 22:40   #5
rn0dal
 
Sep 2004

22 Posts
Default

it gives me this error:
Variable area full. in 20


Thats why I asked the question.thanks a lot for your time, and for the tip (i-2).

-r
rn0dal is offline   Reply With Quote
Old 2004-09-14, 23:49   #6
rn0dal
 
Sep 2004

416 Posts
Default

Never mind last post, how can increase the range?so i can enter a big number,you know so I can enter the bigest number allowed by UBASIC, I dont know maybe there is a way of declaring the array so it can get bigger than 300, I want to be able to use the biggest posible number.thanks a lot for your time.
rn0dal is offline   Reply With Quote
Old 2004-09-15, 14:57   #7
jocelynl
 
Sep 2002

2·131 Posts
Default

Ubasic use a stack of 65536
The dim can't be larger than 32768 * 2 words for small integers dim x%()
when not using the % Ubasic use 542 words to store each numbers

you can reduce the number of words used by ubasic
in help look under (word)

Joss
jocelynl is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to init an array in Posix bc? ewmayer Linux 29 2018-03-08 21:42
Array vs Hash Table vs Map for QS Sam Kennedy Programming 1 2012-12-25 23:25
ubasic: overflow? Andi47 Programming 7 2009-02-27 00:20
ubasic question - strings Andi47 Programming 5 2008-12-28 05:52
array of bits Citrix Programming 2 2005-08-21 20:06

All times are UTC. The time now is 08:31.

Sat Jan 16 08:31:20 UTC 2021 up 44 days, 4:42, 0 users, load averages: 2.47, 2.11, 1.89

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.