Questions tagged [modulus]

The remainder of the quotient of two numbers (usually integers).

847 questions
-6
votes
2 answers

problems while using modulus (%)

class IfElse { public static void main (String[] args) throws java.lang.Exception { double x = 1784; while (x <= 1){ if((x % 2) = 0){ x = x / 2; } else{ x…
-6
votes
2 answers

How to modulus using java?

First 300 meters is 20 fee, succeeding 200 meters is 2 fee. I want to compute distance in meters. input: 300 output: 20 input: 500 output: 22 input: 700 output: 24 public static void main(String [] args){ Scanner sc = new Scanner(System.in); …
-6
votes
4 answers

How modulus operation works in C++?

Why do I get this output: 0 1 2 3 0 1 2 3 0 1 after running the code below? Doesn't the modulus operation finds the remainder after division of one number by another? #include using namespace std; int main () { for (int i=0; i< 10;…
Jack
  • 11
  • 5
-7
votes
1 answer

C# How do i reverse modulus when using a ^ sign

At the moment i have this formula: 13^2 mod 5 = 4 I want to calculate back the 2 here like: 13^X mod 5 = 4 X = ? I found several formula's/codes to do this online but i didn't find any which do it with a ^ symbol. Would appreciate some help My…
Mika SD
  • 1
  • 1
  • 4
-7
votes
3 answers

Why in python -11%5 evaluate to 4?

I am familiar with the usual mod result but not for negative numbers. What is the logic?
-8
votes
2 answers

Can anyone explain why abs(10) % 100 = 10?

I'm doing some practice tasks for school and theres one simple one to make a program that returns the last two digits of any integer over 9. I found the solution online and it uses 'abs()' which I haven't seen before. somehow it made 10 % 100 = 10…
j_yerbe
  • 111
  • 1
  • 9
-10
votes
4 answers

Understanding modulus

I don't really understand how modulus division works. I was calculating 5 % 6 and wound up with 5 and I don't understand why. I understand modulus without decimal values. E. G 16%3 = 5 r 1.
bgreatfit
  • 55
  • 1
  • 10
1 2 3
56
57