This sounds like an exercise regarding functions rather than actually squaring and cubing.. you'd want something like:
.. Pseudocode, as you can see, is pretty easy to read. You could also use x^2 and x^3, but in many programming languages it's easier to just multiply, so I used that notation.
How do I knit a square of one color inside a square of another color?
This is called Intarsia or Picture Knitting.
When you change colors, make sure you have brought the yarn around the first color so that it doesn't leave a gap.
There is a simple diagram at the bottom of this page under Intarsia that shows you how to do it:
How can any number be squared with a racial if its not a square number?
42² = 42 x 42 = 1764
The square root of 42 is irrational, so you can only give an approximate decimal representation. It has an infinite number of digits so you can get it as closse as you want
√(42) ≈ 6.48074
6.08074 x 6.08074 = 41.9999999476. Close enough for any engineering work!