I followed the steps of Euclid’s algorithm but I was stunned when a divide by zero problem appeared. I don’t know how it can happen. Answer The problem is with the below two lines. First statement will make a[0] as 0 since c is 0. Next statement will be 1/0.
Tag: division
division in java programming
The same formula gives different answers to 2296 and 1500, when the expected answer in both cases is 100. Please explain this behavior. I’m quite surprised by this simple thing. Initially I thought this must be due to operator precedence but I cannot understand this. program with 2296 : output: first formula ===>100 alternate formula =====>104 same program with 1500:
Determining divisibility of number by 11 for large numbers
I’m looking for a way to determine a large number is divisible by 11 My understanding: (sum of digits at even positions – sum of digits at odd positions) % 11 == 0 ==> yes This works for some examples. Example: 3816 => (3+1) – (8+6) = -10 In case of negative, do we need to consider 2’s complement of
How do I check divisibility in Java?
I am trying to check if on number is divisible by another, and currently I use this method: Is there a simpler way? Answer You can use modulus operator like this in your condition,