How to resolve the algorithm Sum multiples of 3 and 5 step by step in the Lingo programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sum multiples of 3 and 5 step by step in the Lingo programming language
Table of Contents
Problem Statement
The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sum multiples of 3 and 5 step by step in the Lingo programming language
Source code in the lingo programming language
on sum35 (n)
res = 0
repeat with i = 0 to (n-1)
if i mod 3=0 OR i mod 5=0 then
res = res + i
end if
end repeat
return res
end
put sum35(1000)
-- 233168
You may also check:How to resolve the algorithm Primality by Wilson's theorem step by step in the Lua programming language
You may also check:How to resolve the algorithm Sparkline in unicode step by step in the R programming language
You may also check:How to resolve the algorithm Window creation step by step in the Pascal programming language
You may also check:How to resolve the algorithm Comma quibbling step by step in the APL programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the Groovy programming language