How to resolve the algorithm Sequence of non-squares step by step in the Fortran programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sequence of non-squares step by step in the Fortran 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 Fortran programming language
Source code in the fortran programming language
PROGRAM NONSQUARES
IMPLICIT NONE
INTEGER :: m, n, nonsqr
DO n = 1, 22
nonsqr = n + FLOOR(0.5 + SQRT(REAL(n))) ! or could use NINT(SQRT(REAL(n)))
WRITE(*,*) nonsqr
END DO
DO n = 1, 1000000
nonsqr = n + FLOOR(0.5 + SQRT(REAL(n)))
m = INT(SQRT(REAL(nonsqr)))
IF (m*m == nonsqr) THEN
WRITE(*,*) "Square found, n=", n
END IF
END DO
END PROGRAM NONSQUARES
You may also check:How to resolve the algorithm Tokenize a string step by step in the Transd programming language
You may also check:How to resolve the algorithm Higher-order functions step by step in the AmigaE programming language
You may also check:How to resolve the algorithm Rename a file step by step in the D programming language
You may also check:How to resolve the algorithm Loop over multiple arrays simultaneously step by step in the Salmon programming language
You may also check:How to resolve the algorithm Letter frequency step by step in the Aikido programming language