How to resolve the algorithm Happy numbers step by step in the ALGOL 68 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Happy numbers step by step in the ALGOL 68 programming language
Table of Contents
Problem Statement
From Wikipedia, the free encyclopedia:
Find and print the first 8 happy numbers. Display an example of your output here on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Happy numbers step by step in the ALGOL 68 programming language
Source code in the algol programming language
INT base10 = 10, num happy = 8;
PROC next = (INT in n)INT: (
INT n := in n;
INT out := 0;
WHILE n NE 0 DO
out +:= ( n MOD base10 ) ** 2;
n := n OVER base10
OD;
out
);
PROC is happy = (INT in n)BOOL: (
INT n := in n;
FOR i WHILE n NE 1 AND n NE 4 DO n := next(n) OD;
n=1
);
INT count := 0;
FOR i WHILE count NE num happy DO
IF is happy(i) THEN
count +:= 1;
print((i, new line))
FI
OD
You may also check:How to resolve the algorithm Execute Computer/Zero step by step in the Python programming language
You may also check:How to resolve the algorithm Unix/ls step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Repeat a string step by step in the Ursala programming language
You may also check:How to resolve the algorithm Anagrams step by step in the Ursala programming language
You may also check:How to resolve the algorithm Word frequency step by step in the Mathematica / Wolfram Language programming language