How to resolve the algorithm Factors of an integer step by step in the NetRexx programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Factors of an integer step by step in the NetRexx programming language

Table of Contents

Problem Statement

Compute the   factors   of a positive integer. These factors are the positive integers by which the number being factored can be divided to yield a positive integer result. (Though the concepts function correctly for zero and negative integers, the set of factors of zero has countably infinite members, and the factors of negative integers can be obtained from the factors of related positive numbers without difficulty;   this task does not require handling of either of these cases). Note that every prime number has two factors:   1   and itself.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Factors of an integer step by step in the NetRexx programming language

Source code in the netrexx programming language

/* NetRexx ***********************************************************
* 21.04.2013 Walter Pachl
* 21.04.2013 add method main to accept argument(s)
*********************************************************************/
options replace format comments java crossref symbols nobinary
class divl
  method main(argwords=String[]) static
    arg=Rexx(argwords)
    Parse arg a b
    Say a b
    If a='' Then Do
      help='java divl low [high] shows'
      help=help||' divisors of all numbers between low and high'
      Say help
      Return
      End
    If b='' Then b=a
    loop x=a To b
      say x '->' divs(x)
      End

method divs(x) public static returns Rexx
  if x==1 then return 1               /*handle special case of 1     */
  lo=1
  hi=x
  odd=x//2                            /* 1 if x is odd               */
  loop j=2+odd By 1+odd While j*j
    if x//j==0 then Do                /*Divisible?  Add two divisors:*/
      lo=lo j                         /* list low divisors           */
      hi=x%j hi                       /* list high divisors          */
      End
    End
  If j*j=x Then                       /*for a square number as input */
    lo=lo j                           /* add its square root         */
  return lo hi                        /* return both lists           */

  

You may also check:How to resolve the algorithm Function frequency step by step in the C programming language
You may also check:How to resolve the algorithm Check that file exists step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Collections step by step in the Elena programming language
You may also check:How to resolve the algorithm Metaprogramming step by step in the Raku programming language
You may also check:How to resolve the algorithm Hash join step by step in the M2000 Interpreter programming language