Questions tagged [modulo]

The modulo (sometimes called modulus) operation finds the remainder of division of one number by another. It's typically represented by the percent ('%') character in programming languages.

The modulo (sometimes called modulus) operation finds the remainder of division of one number by another. It's typically represented by the percent ('%') character in programming languages.

For example, assuming % as the character representing this operation, the expresssion 8 % 3 would yield a result of 2: the remainder after dividing 8 by 3.

1648 questions
-1
votes
2 answers

Understanding Remainder operator

Just doing some basic modulo operations and trying to wrap my head around the below operations with questions marks. 0%5 // 0 - Totally understand 1%5 // 1 ? 2%5 // 2 ? 3%5 // 3 ? 4%5 // 4 ? 5%5 // 0 - Totally understand Perhaps I'm thinking in…
Samuel
  • 5,529
  • 5
  • 25
  • 39
-1
votes
3 answers

Program Exits Before Finishing

Question below context Context: For this program to be submitted and work properly I need to be able to input 8.68 for the amount that gets scanned in. The program then needs to be able to calculate how many of each coin type needs to be given as…
-1
votes
2 answers

A beginner question for Modulo with exponentiation calculation

The question is below but how is it calculated in Py and what command should I be entering in Py? Suppose you have $100, which you can invest with a 10% return each year. After one year, it's 100×1.1=110 dollars, and after two years it's…
Rahul John
  • 11
  • 2
-1
votes
2 answers

which is faster to find the even number if(n%2==0) or if(n&1==0)?

which is faster to find the even number if(n%2==0) or if(n&1==0) ? def isEven(n): if n%2 == 0: return True return False OR def isEven(n): if n&1 == 1: return False return True
Beginner
  • 33
  • 4
-1
votes
3 answers

how would I write "while( x/y is not a multiple of 4)"

I am relatively new to programming and I want to it to loop in a "do while" loop while the quotient of two variables is not a multiple of 4.
Ratatosk1
  • 65
  • 4
-1
votes
1 answer

Why is the modulo and division used in the matrix function?

Actor[][] toMatrix(Actor[] arr) { int size = (int) round(sqrt(arr.length)); Actor[][] matrix = new Actor[size][size]; for (int i = 0; i < arr.length; i++) { *** matrix[i / size][i % size] = arr[i]; *** } return…
Netizen110
  • 1,644
  • 4
  • 18
  • 21
-1
votes
1 answer

How to use modulo while browsing a file in a function in C

I don't know how to code a function that browse a file with a specific modulo. Example, if I have 3 as modulo and a file is containing : abcdefghijk then, my function should returns : adgj My code of the function: char f1(char* name_file, int…
-1
votes
3 answers

Quarter End Date

What would be the easiest way for me to assign my quarter end month based upon the month im in? Is there something i can use like modulo? I want the simplest case and least amount of lines of code My quarter ends months are months 3,6,9 and 12. I…
abarz12
  • 27
  • 1
  • 4
-1
votes
1 answer

How to find the fourth thursday of november for any year?

I am trying to find the fourth Thursday of November (thanksgiving day) of any user inputted year. I used the following function to find the day of December 31'st of the previous year of user inputted year. int yr; int…
San Mo
  • 31
  • 5
-1
votes
2 answers

How to get a sublist of all other elements while iterating?

Using list comprehension I can easily do the following: l = [0, 1, 2] for i in l: subl = [j for j in l if j != i] Is there a non-list comprehension way to do this by manipulating indices with the % operator? Edit To clarify: the indices match…
Sam Hammamy
  • 10,819
  • 10
  • 56
  • 94
-1
votes
3 answers

Modulo, float number

How to use modulo for float numbers? For example, how to find the result of select power(cast(101 as float),50)%221
yanzi
  • 31
  • 1
  • 1
  • 3
-1
votes
1 answer

Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’ with Modulo

I tried to solve the next problem from geeksforgeek website. Given an array of size n where all elements are in range from 0 to n-1, change contents of arr[] so that arr[i] = j is changed to arr[j] = i. I saw a solution using modulo: during one…
kicklog
  • 109
  • 2
  • 8
-1
votes
1 answer

z3 c++ api modulo operation with integer

Is there a way to do a modulo operation with z3 c++ api with integers? I'm trying to do something like this: var = context->int_const("foo"); var = var + 1; expr = var % 5; It seems there is only a modulo operation for bitvectors? Am I missing…
toebs
  • 389
  • 1
  • 2
  • 13
-1
votes
2 answers

Python Modulo Function

I understand that the Modulo function returns the remainder of a division problem. Ex: 16 % 5 = 3 with a remainder of 1. So 1 would be returned. >>> 1 % 3 Three goes into 1 zero times remainder 1 1 >>> 2 % 3 Three goes into 2 zero times…
Jeff Schneider
  • 11
  • 1
  • 1
  • 3
-1
votes
1 answer

What is the highest suitable integer for rolling modulo hasing?

Given an algorithm that uses an modulo hash function, meaning big numbers bigger than a certain given integer will "wrap around" so the result is always in between 0 and the given integer. For example the Rabin-Karp Algorithm needs a rolling hash,…
Rich_Rich
  • 427
  • 3
  • 15
1 2 3
99
100