0
How to use the module??
4 Antworten
+ 8
Guys, let me explain it. Function modulo is easy.
For example 14 modulo 3. We must find number, which is smaller than 14 (<14), can be divided ( /) and it will be rational number (1, 2, 3... Not numbers like 3,123). It's 12 (12/3=4). Then we just subtract 14 and 12 (14-12). It's 2.
9 modulo 2= number which is <9 and can be /2. 8 is lower than 9 and can be divided by 2. Then just 9-8=1
Have a nice day :)
+ 1
Modulo is used to find out what is left when you divide a number through another one.
Let's give an example here. If you normally divide 4 with 2, the result you get is 2,
because two fits two times into four.
If you say 4 modulo 2, the result will be 0.
You will be wondering why. It's because there is no rest left, two fits perfectly two times into four.
Nothing more or less needed.
So now, let's use a number where this is not the case.
5 divided through 2 is...?
2.5, yes, but we have to work with whole numbers here in this case. So 5/2 is 2 with a rest of 1.
Because 2x2+1=5
So 5/2 is 2, 5%2 is 1.
Modulo will always be positive or 0.
Just some more examples here, on the left side division, on the right side modulo:
10/1=10 10%1=0
10/2=5 10%2=0
10/3=3 (leaving 1) 10%3=1
10/7=1 (leaving 3) 10%7=3
10/8=1 (leaving 2) 10%8=2
10/10=1 10%10=0
10/11=0 (leaving 11) 10%11=11
+ 1
1. Modulo operator:
It just gives the remainder when we divide the number in the left with the number in the right.
EX- 10 % 3; when we divide 10 by 3 then we have 1 as a remainder. So, 10 % 3 = 1
2. Pre/Post Increment/Decrement:
If you look at it, its pretty easy. If ++ or -- are before then we first increment/decrement then assign. And if ++ or -- are after the variable then we first assign then increment/decrement.
EX- $a=2; $b=9;
case1: $c=$a++; $d=$b++; here we will assign first and then increment. So, final values are, $c=2, $d=9, $a=3, $b=10
case2:$c=--$a; $d=--$b; here we will first decrement then assign. So, final values are, $c=1, $d=8, $a=1, $b=8
+ 1
thanks guys you really helped me