Jump to content

Square but not cube: Difference between revisions

m (→‎{{header|Commodore BASIC}}: Fix inner loop goto target)
Line 1,605:
}</lang>
 
{{output}}
<pre>
Same as Ring example.
</pre>
 
=={{header|Ksh}}==
<lang Ksh>
 
#!/bin/ksh
 
# First 30 positive integers which are squares but not cubes
# also, the first 3 positive integers which are both squares and cubes
 
######
# main #
######
 
integer n sq cr cnt=0
 
for (( n=1; cnt<30; n++ )); do
(( sq = n * n ))
(( cr = cbrt(sq) ))
if (( (cr * cr * cr) != sq )); then
(( cnt++ ))
print ${sq}
else
print "${sq} is square and cube"
fi
done</lang>
{{output}}
<pre>
70

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.