How to resolve the algorithm Sum multiples of 3 and 5 step by step in the ALGOL 60 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 ALGOL 60 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 ALGOL 60 programming language
Source code in the algol programming language
begin
comment - return n mod m;
integer procedure mod(n,m);
value n, m; integer n, m;
begin
mod := n - m * entier(n / m);
end;
integer i, limit;
real sum;
limit := 1000;
sum := 0;
for i := 1 step 1 until (limit - 1) do
if mod(i, 3) = 0 or mod(i, 5) = 0 then
sum := sum + i;
outreal(1,sum);
end
You may also check:How to resolve the algorithm Binary digits step by step in the Ring programming language
You may also check:How to resolve the algorithm Deal cards for FreeCell step by step in the Clojure programming language
You may also check:How to resolve the algorithm McNuggets problem step by step in the REXX programming language
You may also check:How to resolve the algorithm Hamming numbers step by step in the Julia programming language
You may also check:How to resolve the algorithm Last letter-first letter step by step in the Nim programming language