Smallest square that begins with n: Difference between revisions

Added Algol 68
(→‎{{header|Excel}}: Added an Excel LAMBDA version.)
(Added Algol 68)
Line 4:
Find the smallest &nbsp;(decimal integer)&nbsp; squares that begin with &nbsp; &nbsp; <big> '''n''' </big> &nbsp; &nbsp; for &nbsp; <big> 0 &lt; '''n''' &lt; 50 </big>
<br><br>
 
=={{header|ALGOL 68}}==
<lang algol68>BEGIN # find the smallest square that begins with n for n in 1..49 #
INT max number = 49;
[ max number ]INT square; FOR i TO max number DO square[ i ] := 0 OD;
INT number found := 0;
FOR i WHILE number found < max number DO
INT sq = i * i;
INT v := sq;
WHILE v > 0 DO
IF v <= max number THEN
IF square[ v ] = 0 THEN
# found the first square that starts with v #
square[ v ] := sq;
number found +:= 1
FI
FI;
v OVERAB 10
OD
OD;
# show the squares #
FOR i TO max number DO
print( ( " ", whole( square[ i ], -6 ) ) );
IF i MOD 10 = 0 THEN print( ( newline ) ) FI
OD
END</lang>
{{out}}
<pre>
1 25 36 4 529 64 729 81 9 100
1156 121 1369 144 1521 16 1764 1849 196 2025
2116 225 2304 2401 25 2601 2704 289 2916 3025
3136 324 3364 3481 35344 36 3721 3844 3969 400
41209 4225 4356 441 45369 4624 4761 484 49
</pre>
 
=={{header|ALGOL W}}==
Line 43 ⟶ 77:
41209 4225 4356 441 45369 4624 4761 484 49
</pre>
 
=={{header|AWK}}==
<lang AWK>
3,048

edits