How to resolve the algorithm Count in factors step by step in the BBC BASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Count in factors step by step in the BBC BASIC programming language

Table of Contents

Problem Statement

Write a program which counts up from   1,   displaying each number as the multiplication of its prime factors. For the purpose of this task,   1   (unity)   may be shown as itself.

2   is prime,   so it would be shown as itself.       6   is not prime;   it would be shown as

2 × 3

{\displaystyle 2\times 3}

. 2144   is not prime;   it would be shown as

2 × 2 × 2 × 2 × 2 × 67

{\displaystyle 2\times 2\times 2\times 2\times 2\times 67}

.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Count in factors step by step in the BBC BASIC programming language

Source code in the bbc programming language

      FOR i% = 1 TO 20
        PRINT i% " = " FNfactors(i%)
      NEXT
      END
      
      DEF FNfactors(N%)
      LOCAL P%, f$
      IF N% = 1 THEN = "1"
      P% = 2
      WHILE P% <= N%
        IF (N% MOD P%) = 0 THEN
          f$ += STR$(P%) + " x "
          N% DIV= P%
        ELSE
          P% += 1
        ENDIF
      ENDWHILE
      = LEFT$(f$, LEN(f$) - 3)


  

You may also check:How to resolve the algorithm Summarize and say sequence step by step in the Lua programming language
You may also check:How to resolve the algorithm Generic swap step by step in the Lang5 programming language
You may also check:How to resolve the algorithm Best shuffle step by step in the Python programming language
You may also check:How to resolve the algorithm Number names step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Sleep step by step in the Toka programming language