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
0
votes
1 answer

Divide by two while loop in java

what I'm trying to do is use a while loop to check userNum % 2 > 1 once it hits one i want it to stop and print out all the values of the division so for example if 20 is user num it would generate. 20 / 2 and 10/ 2 and 5/2 and then 2/2 resulting…
Ibrahim
  • 19
  • 1
  • 3
0
votes
2 answers

Counting an integer's divisors without just enumerating them (or estimating if not possible)?

Is it possible to count the divisors an integer has without just checking each one up to sqrt(n)? If not, is there at least a way to estimate or approximate how many divisors there are? For example, 28 has six divisors (1, 2, 4, 7, 14, 28). 15 has…
JesseTG
  • 2,025
  • 1
  • 24
  • 48
0
votes
1 answer

Trying to return first 2 digits in scheme

I'm trying to test if i is less than 3 digits, if it is return it, else, recursively call first2 with i/10 untill it is less than 2 digits. With my logic it seems like 12345 should return 12.345 and I could figure out another way to cut off the…
2316354654
  • 279
  • 2
  • 3
  • 14
0
votes
1 answer

Setter can't modify the field properly

I am encountering a problem when creating a program to solve simple kinematics. I run the program and find out the fields haven't been modified properly . Here is the scrap of my program that initialise the object and setting the variables. public…
HaHaman
  • 3
  • 4
0
votes
3 answers

How can I divide two strings in Ruby with gets.chomp?

I try to divide two strings. Here's the code: puts "Enter a weight in lbs: " lbs = gets.chomp stconversion = 14 stone = lbs / stconversion puts "That is #{stone} stone" I keep getting this error: /home/ubuntu/workspace/lbs to stones.rb:4:in…
Thomas
  • 25
  • 3
0
votes
1 answer

getting around ints and floats with button initialisation for Tkinter calculator

Below is a follow on from this question... Python & Tkinter - buttons command to set label textvariable issue I've finished the calculator but here is the problem: My buttons were all built using a for-loop; function buttons included. I like the…
daansteraan
  • 103
  • 1
  • 5
0
votes
0 answers

Newton-Raphson method in computer's divider

I am building a divider for my MIPS processor ALU for integer division, and also in FPU for single precision floating point division purpose. I have searched lots of algorithms and wanted to find a good solution. Since the design is implemented in…
Shuaiyu Jiang
  • 239
  • 1
  • 3
  • 15
0
votes
0 answers

Why python round mechanism in division different from c and java?

When solving a problem in leetcode, I found: >>> -6/132 -1 in python, which seems a bit weird, as it behaves different from c++ and java. It seems that c++ and java is using round to zero mechanism and python is using round to -∞ mechanism. Did…
WKPlus
  • 6,955
  • 2
  • 35
  • 53
0
votes
3 answers

Mechanics of 'x % y != 0' in C++

Can someone please explain the under-the-hood mechanics of x % y !=0 in C++? It evaluates to 0 if there is no remainder in integer division and it evaluates to 1 if there is any remainder of any amount. I find this to be quite useful, but I'd like…
codeling
  • 19
  • 2
0
votes
1 answer

testing for an integer square root in R

How can I test if the square root of a number is an integer using R? The following all evaluate to FALSE. is.integer( sqrt(25) ) is.integer( sqrt(25L) )
Bastiaan Quast
  • 2,802
  • 1
  • 24
  • 50
0
votes
2 answers

divide parallel arrays C++

I have a question about dividing parallel arrays. I'm fairly new to C++. In my program I'm dividing parallel arrays (atBats[] and hits[], and storing the results in an empty array (batAvg[]. When I divide, the new array remains blank even though the…
0
votes
1 answer

Learning Modular Exponentiation, now have to write the code but seek some pointers please?

I am in the midst of learning 'Modular Exponentiation' and I have to now write the code to bring the two together, within a calculator program within my VB 2013. However, as I am very new indeed to this but my studies rely on this module, I'm hoping…
0
votes
3 answers

Dividing integers by floats resulting in proportional integers

Recently I've came across a hard problem solving while doing a project. And I'd like to ask you guys for a solution / algorithm to solve it, because I'm really struggling to think about a clever idea to do so. I have an arbitrary number of floats:…
Manoel Ribeiro
  • 374
  • 1
  • 12
0
votes
1 answer

Overflow while doing multiplication

I want to calculate value of (N* N *(N+1)/2) mod M where this N can go upto 10^18 and M is at max up to 10^7. I tried to code it but don't know the reason that why it is overflowing. Here is my code : In main I do something like this : long long…
user3840069
  • 765
  • 1
  • 6
  • 20
0
votes
2 answers

Java integer division result as double?

I currently have this code: int kills = 1; int deaths = 2; double kdr = 0; if(kills > 0 && deaths == 0) { kdr = kills; } else if(kills > 0 && deaths > 0){ kdr = kills/deaths; } …
ThatGuy343
  • 2,354
  • 3
  • 30
  • 55