How to resolve the algorithm Sum multiples of 3 and 5 step by step in the dc programming language

Published on 12 May 2024 09:40 PM
#Dc

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

Source code in the dc programming language

[ Sm Sn lm 1 - d ln % - d sm ln / ln lm + * 0k 2 / Ss Lm sx Ln sx Ls ]sm

[ d d d 3 r lmx r 5 r lmx + r 15 r lmx - ]ss

[ 27 P 91 P 65 P 27 P 91 P 50 P 50 P 67 P ]su

[ ll p lsx lux p ll 10 * d sl 1000000000000000000000 >d]sd

1 sl ldx

  

You may also check:How to resolve the algorithm Associative array/Iteration step by step in the ooRexx programming language
You may also check:How to resolve the algorithm Multifactorial step by step in the Maple programming language
You may also check:How to resolve the algorithm Singly-linked list/Traversal step by step in the Forth programming language
You may also check:How to resolve the algorithm Last Friday of each month step by step in the Maxima programming language
You may also check:How to resolve the algorithm Write entire file step by step in the XLISP programming language