The next code is an improvement of the first one, calculationg the numbers divisible by any of the given dividers. This problem can be solved by setting the numbers divisible by one of the divisors of the array P[n]. It is sufficient to note that these numbers are multiples of its divisors. Thus, for each divider must determine the minimum multiple within a range of <a,b>. Then choose the smallest multiples and send the output. If during the search for the smallest number we will get the one that has already been sent to the output, we will replace it at its next multiple. The operation will continue until the minimum number exceeds upper range "b".
'Determination of numbers divisible by any of dividers 'Improved code
input "Enter the lower limit of the range (a)" ; a input "Enter the upper limit of the range (b)" ; b input "Enter the number of dividers" ; n
for i = 1 to n input "Enter the " ; i ; " divider" ; P(i)
if P(i) < 0 then P(i) = -1 * P(i) end if
if a < 0 then V(i) = int(a / P(i)) * P(i) else V(i) = int((a + P(i) - 1) / P(i)) * P(i) end if
print "Subsequent numbers in the range <a,b> divisible by any of the given dividers: " ;
I always use online version of RunBASIC available at www.runbasic.com to run my programs. Now I have checked my code again, and it works fine. For numbers 220 and 160 (also in opposite direction) result is 20. The code is based on Euclidean algorithm en.wikipedia.org/wiki/Euclidean_algorithm I tried to attach a file with screenshot of my calculation, but attachment does not work here.
Last Edit: Sept 3, 2013 9:18:01 GMT -5 by krzysztof