How to resolve the algorithm Sequence of non-squares step by step in the ALGOL 68 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sequence of non-squares step by step in the ALGOL 68 programming language

Table of Contents

Problem Statement

Show that the following remarkable formula gives the sequence of non-square natural numbers:

This is sequence   A000037   in the OEIS database.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sequence of non-squares step by step in the ALGOL 68 programming language

Source code in the algol programming language

PROC non square = (INT n)INT: n + ENTIER(0.5 + sqrt(n));

main: (
 
    # first 22 values (as a list) has no squares: #
    FOR i TO 22 DO
        print((whole(non square(i),-3),space))
    OD;
    print(new line);
 
    # The following check shows no squares up to one million:  #
    FOR i TO 1 000 000 DO
        REAL j = sqrt(non square(i));
        IF j = ENTIER j THEN
            put(stand out, ("Error: number is a square:", j, new line));
            stop
        FI
    OD
)

  

You may also check:How to resolve the algorithm Create a two-dimensional array at runtime step by step in the Elena programming language
You may also check:How to resolve the algorithm Temperature conversion step by step in the Wren programming language
You may also check:How to resolve the algorithm Hello world/Graphical step by step in the LabVIEW programming language
You may also check:How to resolve the algorithm List comprehensions step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Percolation/Site percolation step by step in the J programming language