Solution to exercise
- Refer Here
- Solution
- Check if the number is divisible by all the numbers from start to end
function check_if_divisibly start, end, number
index = start
is_divisible_by_all = True
until index <= end:
if number%index != 0 then
is_divisible_by_all = False
return is_divisible_by_all
index = index + 1
return True
- using the divisible by all in lcm calculations
start = 1
end = 10
lcm = end
lcm_found = False
until lcm_found == False # until lcm not found do the operation continuously
if is_divisible_by_all(start, end, lcm) then
lcm_found = True
print lcm
stop
lcm = lcm + end
start = 1
end = 100
index = start
sum = 0
square_sum = 0
until index <= end
sum = sum + index
square_sum = square_sum + index * index
index = index + 1
result = sum * sum - square_sum
print result
Like this:
Like Loading...