The remainder of the quotient of two numbers (usually integers).
Questions tagged [modulus]
847 questions
2
votes
1 answer
Modulus (Float) vs Branch
Given 2 expressions that do the same thing ([-3.14, 3.14] -> [0, 6.28]):
a > 0? a : a + 6.28
or
fmod(a + 6.28, 6.28)
Is there a general difference between the two in performance?
Edit:
Suppose such an expression is called many times (such that…

KobeSystem
- 53
- 1
- 5
2
votes
3 answers
Trouble with introductory programming with C program regarding division and modulus
I apologize for the poor title, and I wish to be more specific, however I am in an introductory programming course, and I don't have much programming experience. The problem I have been given states that I need to find the total amount of rope to…
user10307967
2
votes
1 answer
Java, find 182.5 % (365 / 12)
I want to find the quotient and remainder using Java, but am having difficulty when repeating decimals are involved.
Take the following equations for example (tested with Google calculator):
division: 182.5 / (365 / 12) = 6
remainder: 182.5 % (365 /…

nanoai
- 25
- 3
2
votes
2 answers
How to find reverse of pow(a,b,c) in python?
pow(a,b,c) operator in python returns (a**b)%c . If I have values of b, c, and the result of this operation (res=pow(a,b,c)), how can I find the value of a?

dontholdthelittlefella
- 91
- 1
- 2
- 12
2
votes
2 answers
Sympy Matrix M (modulo n)... How?
import sympy
I am trying to find a matrix after taking each of its values (mod n).
I know numpy arrays work fine with this but i have to use sympy unfortunately.
Does anyone know of an inbuilt sympy function that does this or any other way round…

ANTZY21
- 65
- 6
2
votes
4 answers
Check if cyclic (modulo 16) number is larger than another?
I have two a cyclic integer, modulo 16, so they assume values between 0 and 15.
I need to compare two numbers to determine if n_1 is greater than n_0
n_1 > n_0
Obviously, this is not exactly defined, so I define n_1 to be greater than n_0 if it is…

Bjarke Freund-Hansen
- 28,728
- 25
- 92
- 135
2
votes
1 answer
Identity element of modulus operator to be used in fold
In fold function in functional paradigm, we pass and accumulator value which is generally initialized as the identity element of the operator the function applies.
Like for addition over a list it will be 0, for multiplication 1, and so on.
i.e.,…

Abhishek
- 125
- 8
2
votes
2 answers
Number of Odds and Evens in a List Function - Python
I am trying to create a function called "odd_even" which takes my already created list (named "nums") and determines the number of odd and even numbers, and then returns the variables to me. However when I run this code I get:
NameError: name 'odd'…

Matthew Thibodeau
- 161
- 3
- 14
2
votes
1 answer
How can I get the modulus in C#?
TL;DR:
int remainder = -1 % 5; //-1
int modulus = -1 modulus 5; //4 How do I do this?
I am trying to read the modulated value of an array. So the index modulated by the array length would be the updated index. For example:
array = {100, 200,…

Evorlor
- 7,263
- 17
- 70
- 141
2
votes
2 answers
Python : Modulus operator giving incorrect result
I am fairly new to Python and I am trying to implement the Hill Cipher as a small project. I think I have the logic figured out and have got the encryption part to work, however, in the decryption part, I am facing troubles. Especially with the…

Chaos
- 37
- 7
2
votes
4 answers
deciding if a number is perfect or prime
the problem is :
"Write a function to find out if a number is a prime or perfect number."
so far i have worked on the perfect part first and this is what i have:
#include
using namespace std;
bool perfectNumber(int);
int main()
{
int…

carla
- 169
- 1
- 2
- 7
2
votes
1 answer
Using a modulus operator to get a random variable in a certain range
Sorry, I know there are similar questions already posted but this book is confusing me nonetheless.
In "C Programming: Absolute Beginner's Guide", there is a line:
dice1 = (rand() % 5) + 1;
to generate a random number between 1 to 6 for a dice…

5areductase
- 269
- 2
- 10
2
votes
2 answers
Modulus in Assembly x86
My professor gave me an assignment to convert this C code into Assembly code
int k = 0, S = 0;
for (k=0; k<100; k++)
{
if (k%2 == 0)
S += k;
else
S -= k;
}
Assembly is only a small part of my course, so we haven't gotten into a lot of the technical…

Axel1212
- 143
- 2
- 10
2
votes
3 answers
PHP echo in rows of three?
I am attempting to show data in rows of three like this (notice the number of items will not always be even):
abcd defg hijk
lmno pqrs tuvw
xyz1 2345 6789
1011 1213
I am struggling to get the logic right to do this (this is in a foreach()…

Hailwood
- 89,623
- 107
- 270
- 423
2
votes
1 answer
Ada mod and rem implementation
When looking into exactly what the difference is between mod and rem (something I admittedly should have done years ago, I found little on the matter. https://en.wikipedia.org/wiki/Modulo_operation states there are a few different divisions that can…

Patrick Kelly
- 633
- 5
- 22