The remainder of the quotient of two numbers (usually integers).
Questions tagged [modulus]
847 questions
-1
votes
2 answers
Strange Modulus Operator Result - PHP
I am working on a PHP application and mathematical operation was resulting wrong answer which was displaying wrong results. So, I started digging down and after few hours effort I was able to detect the issue.
Here is the problematic…

Alena
- 1,134
- 6
- 19
- 45
-1
votes
1 answer
Value of remainder
I am looking for a way to extract the fractional part of a number in python. I am fairly new to Python and have dabbled in MatLab in college, nothing serious. I understand that the % operator reports the quantity of number placements in the…

user8371532
- 3
- 3
-1
votes
1 answer
Modulus operator not behaving as expected in javascript?
I have the following:
-1 mod 5
I expect to get 4.
However in JS (-1 % 5), I'm getting -1.
What am I doing wrong?

SB2055
- 12,272
- 32
- 97
- 202
-1
votes
1 answer
JavaScript (erroneously?) only applying modulus to operation with this one syntax
I'm trying to increment a variable and return it to 0 if it hits a certain number. Logically I tried
i++ % number
but the variable kept incrementing.
I looked it up and found this answer, which works:
i = (i + 1) % 3
And I didn't understand why.…

JackHasaKeyboard
- 1,599
- 1
- 16
- 29
-1
votes
2 answers
how does a modulus work when you want to print set of numbers per line
Can someone please explain to me how does the modulus work if you wanna print set of numbers per line like in the given code below? I only know that the role of the modulus is to give the remainder of a number and that's about it. I would like to…

Blue Eagle
- 55
- 8
-1
votes
1 answer
incorrect output - modulus not properly calculating
I need the program to print out a statement providing the child adult height in a decimal format of feet (using the modulus) (for ex if the child's height is 5'7" the display should read "The child's adult height would be 5.58'
import…

Lisa
- 1
- 1
- 2
-1
votes
1 answer
Loop with modulus gives me an error
this is my first time posting a question, but this loop drove me crazy. I cant figure out what is wrong with it. It crashes at the moment when it enters the second loop. It looks fine and makes sense but still it does not work. Any help will be…

Yunus Kulyyev
- 1,022
- 15
- 26
-1
votes
1 answer
How to change colour of successive user inputted words based on checkboxes
I need to basically have five checkboxes, all with different colors. Whatever the user types in after clicking needs to be printed to the screen as successive colors based on what boxes are checked. Ie: If blue and yellow are ticked then the first…

StayTuned110
- 1
- 2
-1
votes
1 answer
Make summing power series more efficient
I am coding in hackerrank and came across this problem:
https://www.hackerrank.com/challenges/power-calculation
My code works for small files and big numbers. As for the big files, it times out. Could someone make it more efficient.
My code:
z =…

qwerty
- 49
- 9
-1
votes
3 answers
Weird python power module result
According to these answers there is not difference between pow(a,b) and a**b. However, math.pow(a,b) returns a float value. Now, when running the following python code something strange happens:
>>>import…

Squeek
- 33
- 7
-1
votes
3 answers
TypeError for Python program (string formatting with %d)
My program: A Math Quiz that prompts a user for a choice of difficulty (Beginner, Intermediate, Advanced) and then generates five questions (with random #'s) depending on their choice.
It was working completely fine until I started adding the…

ch695
- 1
-1
votes
1 answer
Modulus and Binary Numbers
#include
using namespace std;
int main()
{
int index = 0;
int val;
int x;
while (val != 0)
{
cin >> val;
for (index = 1; index < 32; index++)
{
x = val * index - index / index;
cout…

mydiax
- 41
- 10
-1
votes
3 answers
String decoder not working properly
I am converting letters in a string to their corresponding numbers and printing YES if the result is divisible by 6 or NO. For eg, ab is 12 and will give YES. The program is working fine for small strings but gives wrong answer for very long…

Rachit Ajitsaria
- 13
- 8
-1
votes
5 answers
-1
votes
1 answer
Good practice on optimal repartition of files in folders
I have some files with number as names I want to put in folders on a optimized way such as about same number of files per folder et al.
Would it be a good practice to choose the folder after the modulus of the number ? Is modulus as expensive as…