Skip to main content
6 of 8
edited tags
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Calculate the square of an integer with restrictions

The Puzzle

You have to write a program or function p(n) that returns the square of what is entered into it and you may assume that the input is a non-negative integer. Put in simpler terms, return n2.

Rules

  1. You are not allowed to use * or / (or any other power or square root operator, such as POW or SQRT, if your program contains such functions)
  2. You may not use a loop, or use a constructions that is similar to a loop. Example of loop like constructions are GOTO and recursion.

Example

Function p(n)
Dim r()
ReDim r(n)
p = Len(Join(r, Space(n)))
End Function

Be create and (ab)use the functions and features given to you by your language of choice.

dwana
  • 551
  • 4
  • 8