text: Calculate square of a number without using * , / and pow ( ) | Simple solution to calculate square without using * and pow ( ) ; handle negative input ; Initialize result ; Add n to res n - 1 times ; Driver code
code: function square ( n ) { if ( n < 0 ) n = - n ; let res = n ; for ( let i = 1 ; i < n ; i ++ ) res += n ; return res ; } for ( let n = 1 ; n <= 5 ; n ++ ) document . write ( " " + n + " " + square ( n ) + " " ) ;