|
I'm solving some Euler problems, and the % operator is very useful. I take it to mean 'false is a number is divisible by n', or: So what's the opposite of it? Some variant of !%
(comments are locked)
|
|
It's called the Modulus operator, and it returns the remainder of an equation. Ex:
Check the docs for a more in depth example: http://msdn.microsoft.com/en-us/library/h6zfzfy7%28v=vs.80%29.aspx The opposite would be a division operator applied to integers, thus ignoring the remainder. Ex:
Nice answer, thanks, upvote.
Jan 10 '12 at 10:58 AM
Muzz5
(comments are locked)
|
|
Well as they above explain, its a remainder. Actually, this is not valid in C#. So you're probably using UnityScript and unity script converts this into something like That being said: If you use modulo, the correct way of doing it is or I would mark your answer right, as it's got some good examples, but the other one had more votes, so I'll just upvote yours.
Jan 10 '12 at 10:59 AM
Muzz5
You vote the answer which is right for you, not which other have chosen or voted up. It's not democratic hehe :)
Jan 12 '12 at 08:50 PM
Tseng
(comments are locked)
|
|
I think there is not really an opposite of %, because x%y mean a number (except when y=0 - division by zero error). 6!%2 for example, does not make too much sense for me (looks like 'if is not possible to divide 6 with 2'). The simplest solution for you to use % is:
Actually: Please don't provide this kind of code behavior/pattern. It's plain wrong. The expression inside of
Jan 10 '12 at 02:27 AM
Tseng
@Tseng Ahh, Thx! My inadvertently. I have it edited. if(n%2) = 0 to if(n%2== 0)
Jan 10 '12 at 09:59 AM
nastasache
(comments are locked)
|

also just look for C# on Google. You will usually find a link to Microsoft where they explain the language of their own.