How to resolve the algorithm Primality by trial division step by step in the ALGOL 68 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Primality by trial division step by step in the ALGOL 68 programming language

Table of Contents

Problem Statement

Write a boolean function that tells whether a given integer is prime.

Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Primality by trial division step by step in the ALGOL 68 programming language

Source code in the algol programming language

main:( 
  INT upb=100;
  printf(($" The primes up to "g(-3)" are:"l$,upb));
  FOR i TO upb DO 
    IF is prime(i) THEN
      printf(($g(-4)$,i))
    FI
  OD;
  printf($l$)
)

  

You may also check:How to resolve the algorithm Primes - allocate descendants to their ancestors step by step in the 11l programming language
You may also check:How to resolve the algorithm Sorting algorithms/Heapsort step by step in the COBOL programming language
You may also check:How to resolve the algorithm Four is magic step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Increment a numerical string step by step in the OoRexx programming language
You may also check:How to resolve the algorithm Range extraction step by step in the MATLAB / Octave programming language