0

Let $x$ be an integer which can take a value of $0$ or $1$. The statement

if $(x = = 0) x = 1;$ else $x = 0;$

is equivalent to which one of the following ?

  1. $x = 1 + x;$
  2. $x = 1 - x;$
  3. $x = x - 1;$
  4. $x = 1\% x;$

My attempt :

It should be only option $(2)$ is true. but,

Can you explain little bit please, what is the value of $1\%0$ ?

AFAIK: It should be undefined, since it applied division $1/0$ which is undefined.

  • 1
    This sounds more like a programming question than a mathematics one. I suspect as code it would throw a run time error if you tried to do mod zero. – Ian Miller Nov 18 '15 at 13:36
  • 1
    Mathematicians tend not to use % as an operator, and we tend not to assign variables new values. This is a coding problem? The best definition would be that $a%0==a$ for all $a$, but who knows what it would be in the language at hand - depends precisely on the definition. – Thomas Andrews Nov 18 '15 at 13:36
  • You can find your answer over here - http://math.stackexchange.com/questions/516251/why-is-n-mod-0-undefined – mihir Nov 18 '15 at 13:37
  • If you are talking about the C programming language, then the behaviour of 1%0 is undefined, see for example http://stackoverflow.com/questions/7370154/cant-mod-zero. That might be different for other programming languages. – Martin R Nov 18 '15 at 13:37
  • Mathematicians typically use = for equations, and indicate the assignment of a new value as := or a leftward pointing $\mapsto$ (not sure what the symbol for this is). In your case, since $x$ is boolean, the assignment can be written as $x := NOT x$ or $x := 1-x$, since the assignment inverts TRUE and FALSE. – Marconius Nov 19 '15 at 00:15

1 Answers1

1

"$1\%0$" would be equivalent to $1-\Big\lfloor\frac10\Big\rfloor\times0$.

Modulo by $0$ is as meaningless as Division by $0$.

barak manos
  • 43,109