Smallest square that begins with n: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added a foot separator for the output.) |
Not a robot (talk | contribs) (Add Cowgol) |
||
Line 426: | Line 426: | ||
484 |
484 |
||
49</pre> |
49</pre> |
||
=={{header|Cowgol}}== |
|||
<lang cowgol>include "cowgol.coh"; |
|||
sub beginsWith(a: uint16, b: uint16): (r: uint8) is |
|||
while a > b loop |
|||
a := a / 10; |
|||
end loop; |
|||
if a == b then r := 1; |
|||
else r := 0; |
|||
end if; |
|||
end sub; |
|||
sub smallestSquare(n: uint16): (sq: uint16) is |
|||
var sqn: uint16 := 1; |
|||
loop |
|||
sq := sqn * sqn; |
|||
if beginsWith(sq, n) != 0 then |
|||
return; |
|||
end if; |
|||
sqn := sqn + 1; |
|||
end loop; |
|||
end sub; |
|||
var n: uint16 := 1; |
|||
while n < 50 loop |
|||
print_i16(smallestSquare(n)); |
|||
print_nl(); |
|||
n := n + 1; |
|||
end loop; |
|||
</lang> |
|||
{{out}} |
|||
<pre style='height:50ex;'>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|Excel}}== |
=={{header|Excel}}== |