I know this is probably a very simple question but how would I do something like n2 in a programming language?
Is it n * n? Or is there another way?
n * n
is the easiest way.
For languages that support the exponentiation operator (**
in this example), you can also do n ** 2
Otherwise you could use a Math library to call a function such as pow(n, 2)
but that is probably overkill for simply squaring a number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With