How to resolve the algorithm Sum multiples of 3 and 5 step by step in the FutureBasic 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 FutureBasic 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 FutureBasic programming language

Source code in the futurebasic programming language

include "NSLog.incl"

_n = 1000

void local fn DoIt
  long i, sum = 0
  
  for i = 0 to _n - 1
    if ( i mod 3 == 0 or i mod 5 == 0 )
      sum += i
    end if
  next
  NSLog(@"%ld",sum)
end fn

fn Doit

HandleEvents

  

You may also check:How to resolve the algorithm Gamma function step by step in the Clojure programming language
You may also check:How to resolve the algorithm Chernick's Carmichael numbers step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm 15 puzzle game step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm Execute a system command step by step in the AppleScript programming language
You may also check:How to resolve the algorithm The Name Game step by step in the Wren programming language