Questions tagged [integer-division]

Anything related to the integer division operation, i.e. that special form of division which is performed between two integer numbers and which in math results in a quotient and a remainder. This is mostly relevant for languages which have specific integer data-types, for which the division is an integer division, or for languages having a specific operator/function to perform integer division.

Anything related to the integer division operation, i.e. that special form of division which is performed between two integer numbers and which in math results in a quotient and a remainder. This is mostly relevant for languages which have specific integer data-types, for which the division is an integer division, or for languages having a specific operator/function to perform integer division.

619 questions
-1
votes
1 answer

Most efficient way to find the greatest number not greater than A, which is divisible by B

I have 2 numbers A and B. I want to find C = A - (A % B), but there are some problems. First of all, if C and D = A / B should have the same parity ((even and even) or (odd and odd)), otherwise C should be incremented (++C). The second problem is…
Bioliquid
  • 161
  • 7
-1
votes
1 answer

Searching for theory on following overflow evasion trick

The following code is using some integer overflow preventation trick that I'm trying to understand: // x,y,z are positive numbers boolean check(long x, long y, long z) { return x >= (z+y-1)/y; } Based on the problem definition, I assume that the…
-1
votes
1 answer

Adjusting quotient of integer division in C++

Example: B+ Trees Given N tuples in the tree, at most di children per inner node and at most dl values per leaf, the minimum height of a B+ Tree would be h = ceil(log_di((N + dl - 1) / dl)) if I am not mistaken. This is only true if / denotes the…
Araeos
  • 171
  • 2
  • 9
-1
votes
1 answer

C output of hexadecimal division different from all other sources

I want to divide two hex numbers: for example: 88555680/10000 Now, from online hex calculators, I find: 8855 as result here 8855.568 as result here And in python I find: >>> hex(int("0x88555680",16)//int("0x10000", 16)) '0x8855' Here is my C…
charelf
  • 3,103
  • 4
  • 29
  • 51
-1
votes
1 answer

Why is (13 / 3 == 4) true?

((13 / 3 == 4) == true) why is this equals true? 13/3 = 4.3333 and 4.333 is not equaled 4. Is it about auto cast into an integer? and round? I tested it in Java EE 8.
J. H
  • 102
  • 11
-1
votes
1 answer

Given a masked number, count all the possible number divisible by n

I have a dynamic programming exercise but I dont know how it will work in here: We have a mysterious number is a string that consists of digits and asterisk *. Given a mysterious number, count all the possible natural number to replace the asterisk…
Justin
  • 149
  • 1
  • 11
-1
votes
1 answer

Division in Python int (1000000000000000000/3)=333333333333333312

In Python int (1000000000000000000/3)=333333333333333312 But it should be: int (1000000000000000000/3)=333333333333333333 I am new to python.
-1
votes
3 answers

C thinking : float vs. integers and float representation

When using integers in C (and in many other languages), one must pay attention when dividing about precision. It is always better to multiply and add things (thus creating a larger intermediary result, so long as it doesn't overflow) before…
Charles
  • 988
  • 1
  • 11
  • 28
-1
votes
4 answers

Incorporate a for loop into integer division

I want to divide one number by another number using integer division until my result is zero and keep track of how many divisions I do. However I keep getting an 'int' object not iterable error whenever I try to incorporate a for loop. My code…
ORM
  • 25
  • 1
  • 4
-1
votes
2 answers

Write a program that prompts the user for the radius of a sphere and prints its volume

Im not getting correct answer with the following code below. Can anyone debug this code? When I input radius = 5, the answer I get is 500.000000 whereas the original answer should be 523.80952. Can anyone please explain what's wrong here? Sphere…
Hamza Azam
  • 17
  • 1
  • 3
  • 10
-1
votes
2 answers

Calculating probabilities in c# by dividing 2 variables

Okay so I'm trying to make a simple console program that calculates the chance of drawing a specific card from a deck of trading cards. At the moment my code looks something like this: using System; using System.Collections.Generic; using…
-1
votes
1 answer

Can anyone explain how this division algorithm works?

I saw this in an algorithm textbook. I am confused about the middle recursive function. If you can explain it with an example, such as 4/2, that would be great! function divide(x, y) Input: Two n-bit integers x and y, where y ≥ 1 Output: The…
Angelo
  • 185
  • 1
  • 2
  • 15
-1
votes
2 answers

What's wrong in this c code?

This is a question on Codeforces, link Find the number of k-divisible numbers on the segment [a , b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k. Input: The only line contains three…
-1
votes
3 answers

C Programming - Average

Okay I'm entirely stuck here and I do apologise if this inconviences you guys in any way but I need your help. I'm currently learning C by myself and slowly getting there, started yesterday. So I thought I would give myself a task on having the user…
-1
votes
4 answers

Quotient from integers in C

I want to get the result of a division of two integers. For example the integers 6 and 25. If I divide the integers I get 6/25 = 0 as the answer. I want the result to be 6/25 = 0.24. How can I do it?