How to resolve the algorithm Count in factors step by step in the Action! programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Count in factors step by step in the Action! 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 Action! programming language

Source code in the action! programming language

PROC PrintFactors(CARD a)
  BYTE notFirst
  CARD p

  IF a=1 THEN
    PrintC(a) RETURN
  FI

  p=2 notFirst=0
  WHILE p<=a
  DO
    IF a MOD p=0 THEN
      IF notFirst THEN
        Put('x)
      FI
      notFirst=1
      PrintC(p)
      a==/p
    ELSE
      p==+1
    FI
  OD
RETURN

PROC Main()
  CARD i

  FOR i=1 TO 1000
  DO
    PrintC(i) Put('=)
    PrintFactors(i)
    PutE()
  OD
RETURN

  

You may also check:How to resolve the algorithm Primes - allocate descendants to their ancestors step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm Chaocipher step by step in the BASIC programming language
You may also check:How to resolve the algorithm Honaker primes step by step in the J programming language
You may also check:How to resolve the algorithm Terminal control/Dimensions step by step in the Python programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Euphoria programming language