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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Factors of an integer step by step in the Seed7 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 Seed7 programming language

Source code in the seed7 programming language

$ include "seed7_05.s7i";

const proc: writeFactors (in integer: number) is func
  local
    var integer: testNum is 0;
  begin
    write("Factors of " <& number <& ": ");
    for testNum range 1 to sqrt(number) do
      if number rem testNum = 0 then
        if testNum <> 1 then
          write(", ");
        end if;
        write(testNum);
        if testNum <> number div testNum then
          write(", " <& number div testNum);
        end if;
      end if;
    end for;
    writeln;
  end func;

const proc: main is func
  local
    const array integer: numsToFactor is [] (45, 53, 64);
    var integer: number is 0;
  begin
    for number range numsToFactor do
      writeFactors(number);
    end for;
  end func;

  

You may also check:How to resolve the algorithm Composite numbers k with no single digit factors whose factors are all substrings of k step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Check if a polygon overlaps with a rectangle step by step in the Raku programming language
You may also check:How to resolve the algorithm Terminal control/Ringing the terminal bell step by step in the Nemerle programming language
You may also check:How to resolve the algorithm Leap year step by step in the LOLCODE programming language
You may also check:How to resolve the algorithm Roman numerals/Encode step by step in the Elixir programming language