|
Does this mean that no matter what number I generate, it will always have to end in 5?
e.g. All these numbers are divisable by 5
39485
99045
12095
49385
99335
However, I was under the impression I could generate numbers that would be divisable by 5, but not end in 5?
Is this wrong?
Regards,
Stephen
|
|
|
|
|
Numbers that end in 0 are also divisible by 5 (except zero)
So you're right.
|
|
|
|
|
|
It depends on the definition of divisibility that you use.
Zero can also be divisible by anything, if you use an other definition.
|
|
|
|
|
BS.
zero times x equals zero, no matter what (finite) value x has.
so (the right side's) zero is divisible by x, and the result is (the left side's) zero.
If I hold 10 pies, 5 bacon sandwiches, and zero glasses of milk, I have no problem distributing them evenly to 5 people.
Next you'll state you could also redefine 5, so it no longer divides itself.
|
|
|
|
|
Luc Pattyn wrote: Next you'll state you could also redefine 5, so it no longer divides itself.
It doesn't. There are only four bacon sandwiches left...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Sorry for the late reply, I have been off-line this evening, I have another tournament going on this week. I trust all bacon sandwiches have magically disappeared by now, and so the problem got solved?
|
|
|
|
|
Nope. You seem to think that that is the only definition of divisibility.
I did not personally redefine anything.
There is no natural number n such that 0/x=n so no x evenly divides 0.
If you use the definition with integers instead of natural numbers, everything divides zero.
Also, the prime factorization of zero is empty.
|
|
|
|
|
natural numbers are the ordinary counting numbers 1, 2, 3, ... (sometimes zero is also included) is what Wikipedia[^] offers as a definition. Now you can choose: either you include zero and you are allowed to use it at both sides of your 0/x=n , or you exclude it (and then your "except zero" remark that started all this is completely irrelevant).
|
|
|
|
|
Yes but that's precisely the point, you can choose.
|
|
|
|
|
That is a stupid definition. It would also indicate that -10 is not divisible by 5. There may be abstruse mathematical concepts for which it's useful, I suppose, but for normal maths it is nonsense.
|
|
|
|
|
x is not a natural number there.
|
|
|
|
|
And your point is? (Neither is 0, right?) Both are representable in the number system, and both divide by 5 in any reasonable definition.
|
|
|
|
|
http://mathworld.wolfram.com/EvenNumber.html[^]
Note zero is an even number and by definition dividable by two, the answer is just zero. As a recall from calculus I, you can't divide a number by zero but you can divide a number as the devisor approaches zero.
ARon
|
|
|
|
|
Actually 0 is divisable by any number.
|
|
|
|
|
Good luck dividing zero by zero.
|
|
|
|
|
I KNEW there was a reason why I liked num -= num%5; better!
How often have you seen a sizable random number generator produce 0 as an answer? (OK, you can easily set your random number limit so *10 will never overflow.)
The original request is divisable by 5 and only affecting the last digit, not the whole number. Lets see: convert the int to a string, take a substring 1 less than the length, add "5" to the string and then convert back to int. There's quite a few ways to get this to work, multiplying by 10 and adding 5 will ONLY work correctly when the random number IS zero.
Exactly where did I say to divide by zero? If num is zero, num=(num/5)*5 will produce zero. The highest numbers in int16, int, and int64 all end in decimal 7 and this process will work in all languages, the lowest number ends in 8. That will work in reasonable languages, VB.NET will blow up with an overflow. (In that language use num=(num\5)*5) (Actually VB is a reasonable language, you just have to know the gotchas like 5/3 is 2, not 1. I spent a little time swearing at its math until I found "\". I haven't found a use for round-up but if I did, VB would actually work quite a bit better than most languages for that.)
Also good luck executing 5/0! (Or ANY other number by 0)
|
|
|
|
|
Sorry, different thread. I did say any number and you are totally right and the rest of my rant was uncalled for.
|
|
|
|
|
Look at what I said - add 5 or 10.
If a number is divisible by 5 it must end in 5 or 0 - that's primary school arithmetic.
If you don't believe me write out the 5 times table for the numbers 1 to 20.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
riced wrote: If a number is divisible by 5 it must end in 5 or 0
Yes; I was getting confused with the coding issue not the actual math.
riced wrote: that's primary school arithmetic.
I know, I am a Biomedical Scientist.
riced wrote: If you don't believe me write out the 5 times table for the numbers 1 to 20.
I do believe you. Like I said, it was the coding side of things. However, it is my fault the way I explained myself, it did indeed look as though I didn’t understand the math itself, and I certainly was not questioning you answer.
Sorry if it came across that way, and thank you.
Kind Regards,
Stephen
|
|
|
|
|
Your confusion did lead me to think - how old is this guy, doesn't understand primary grade maths
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
stephen.darling wrote: riced wrote: that's primary school arithmetic.
I know, I am a Biomedical Scientist.
You are NOT a scientist. A scinetist knows elementary math. You should be ashamed of yourself.
There can be only one.
|
|
|
|
|
mmwlada wrote: You are NOT a scientist. A scinetist knows elementary math. You should be ashamed of yourself.
How dare you!
I may be a beginner in the programming world, but to be spoken to in this way from someone who does not know me is extremely rude!
I am indeed a scientist, registered in the UK as a practising biomedical scientist, not that I need to explain myself to you!
As for the math, if you took the time to read through the post, you would see that I simply explained myself wrong, and it was the programming that I was struggling with, and not the math.
As for being ashamed of myself; I do not know what your problem is, but believe me, I have nothing to be ashamed of, and could now go on to say allot about, and to you, however, I will refrain!
Stephen
|
|
|
|
|
stephen.darling wrote: I have nothing to be ashamed of
Absolutely correct.
I know the language. I've read a book. - _Madmatt
"The OP herself was not sure about her question"
"The OP is from India and I know what she meant."
|
|
|
|
|
Knowing math, and knowing how a make a computer perform math are two completely different things. Your statement is wilding inappropriate.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|