Print all perfect squares from the given range | Function to print all the perfect squares from the given range ; Getting the very first number ; First number 's square ; Next number is at the difference of ; While the perfect squares are from the range ; Print the perfect square ; Get the next perfect square ; Next odd number to be added ; Driver code
function perfectSquares ( l , r ) { let number = Math . ceil ( Math . sqrt ( l ) ) ; let n2 = number * number ; number = ( number * 2 ) + 1 ; while ( ( n2 >= l && n2 <= r ) ) { document . write ( n2 + " " ) ; n2 = n2 + number ; number += 2 ; } } let l = 2 , r = 24 ; perfectSquares ( l , r ) ;