The remainder of the quotient of two numbers (usually integers).
Questions tagged [modulus]
847 questions
-2
votes
1 answer
Why does date.getHours()%12 give you the time in 1-12 format?
I am not understanding why const hours = (date.getHours() + 11) % 12 +1; gives the hours back in 1-12 format? I copied and pasted this code into my program but there was no explanation. Any help in explaining this would really help, thanks.
This is…

Pat8
- 958
- 9
- 19
-2
votes
2 answers
C: Unable to use modulus operators to break down change into denominations, storing into an array and print the output to the user
I'm attempting to write a program in which:
The user inputs the cost of an item
The user inputs the amount they paid for the item
The program determines if the user is owed any change
The program calculates the amount of change owed
The program…

hailnolly
- 33
- 1
- 10
-2
votes
2 answers
How to generate random numbers of unique modulus values in python
import random
value = 1000
a = []
i = 0
b = [None] * 16
print('value = ',1000)
for x in range(value):
a.append(x)
random.Random(4).shuffle(a)
print(a)
for x in range(16):
b[x] = a[x]
print(b)
This code generate 16 random numbers…

JwL
- 43
- 6
-2
votes
3 answers
(java/math) how to find quotient in mod?
This may be a rather simple problem. I'll show an example.
I have A and B (take it as client and server set-up). A does the following
(2^10) mod 23 = 12.
It then sends the value 12 over to B
Now, B has the equation 12 = (2^x) mod 23. (It has the…

dancerdiver101
- 51
- 1
- 6
-2
votes
1 answer
Errors involving precedence of modulus operator and brackets with large numbers in C++
The first part of the just computes some mathematical formula, stroed in ans1, ans2 and ans3. Many sites give % and * as having the same priority in the precedence order. Should we then consider them left to right in an expression? Only difference…
-2
votes
1 answer
Using modulus on a double
I am trying to add up the even numbers and the odd numbers separately from a given array and for some reason I get a 0 as the output for the sum of even numbers and all the values seems to be only added to the sum of odd numbers. I thought that if…

eddie
- 41
- 1
- 6
-2
votes
2 answers
What is the logic behind this algorithm?
The explanation for this problem can be found @ http://www.cemc.uwaterloo.ca/contests/computing/2017/stage%201/juniorEF.pdf
(it's the third problem titled "exactly electrical").
def electrical(a,b,c,d,e) :
charge = e
x_dif = abs(c - a)
…

Eric Hasegawa
- 169
- 1
- 14
-2
votes
1 answer
Division with decimals below zero vb.net
I'm writing a program in vb.net which allows the user to input an amount of money and then outputs the minimum number of coins that are needed to make that amount. For example if the user inputs £3.43 the program would output 1 x £2, 1x £1, 2x £20p,…

J Wilson
- 13
- 5
-2
votes
3 answers
Creating decreasing sequence with (x++)%n in C#
So, I know that with a code snippet such as:
int x = 0; //class field variable
private void button1_Click(object sender, EventArgs e)
{
Label1.Text += (x++)%4 + 1;
}
a sequence of 12341234 is displayed on the form if the button is clicked 8…

ewong18
- 144
- 1
- 2
- 10
-2
votes
1 answer
I have a RSA public key exponent and modulus. How can I encrypt a string using C#?
My Public Key
setMaxDigits(131);
var publicKey = new RSAKeyPair('010001', '',…

Le Tung Anh
- 811
- 6
- 7
-2
votes
1 answer
Javascript Function defaulting to wrong answer (I think)
Hi can somebody tell me why the output to my function defaults to even when you insert over 17 numbers? It's probably super simple, please go easy on me!
function oddOrEven(number) {
var number = document.getElementById('number').value;
…

danboswell
- 17
- 1
-2
votes
1 answer
How to resolve modulus/division by zero error in python
I am struggling to debug the following code, which throws a ZeroDivisionError:
if num > 0:
return filter(lambda x: abs(num) % x == 0, range(1:abs(num))
else:
pass
The error message is:
ZeroDivisionError: integer division or modulo by…

squalor
- 33
- 5
-2
votes
3 answers
Calculating the modulus of a large square
I want to calculate the modulus of a square: n^2 % m, where both n and m are large numbers (but less than the maximum of a 64 bits integer). The problem arrises when n^2 gets larger than the 64 bits maximum.
Is there an algorithm available to do…

Spifff
- 748
- 6
- 14
-2
votes
3 answers
How to determine whether a number is even or odd and then count them in Java
Extremely new to Java, have just started using it in the last 2 weeks in school, we've been given the assignment to make a program to determine whether 5 given intergers are even or odd and then give an output to look like this
Even: 2
Odd: 3
We…

John Alex
- 53
- 7
-2
votes
1 answer
How can % 8 actually return 8?
I have this function for custom padding, which works like this:
var length = 8 - ( (this.buffer.length - 1 + this.buffer.length - 39) % 8);
var padding = Buffer.alloc(length + 1);
for (i = 1; i <= length; i++) {
…

ProTheJoker
- 45
- 7