RosettaCodeData/Task/Square-but-not-cube/UNIX-Shell/square-but-not-cube-1.sh
2023-07-01 13:44:08 -04:00

19 lines
367 B
Bash

# 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