How do I generate a number divisable by 5, and check it?
-
a random multiple of five is bound to be five times some other random number. :omg:
Luc Pattyn [My Articles] Nil Volentibus Arduum
Stating the obvious! 5+ :-D :thumbsup:
"With sufficient thrust, pigs fly just fine."
Ross Callon, The Twelve Networking Truths, RFC1925
-
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
-
David1987 wrote:
except zero
:confused::confused::confused:
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
Generate a four digit random number, multiply it by 10, add 5 (or 10). The result will be divisible by 5.
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis The only valid measurement of code quality: WTFs/minute.
you shouldn't add 5 or 10 but 5 or 0. In the case the random generator provides 9999 then you would get 9999 * 10 + 10 = 99990 + 10 = 100000 six digits
-
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 [My Articles] Nil Volentibus Arduum
-
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 [My Articles] Nil Volentibus Arduum
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... :laugh:
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."
-
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 [My Articles] Nil Volentibus Arduum
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.
-
Hi. First, how would I create a random number, and then add the last digit, so that it is divisable by 5? the number should always be 5 digits long. Second, how do I check it, I think I need to do something like...
if (int x MOD 5 ==0)
Or something like that. The first step is the most important though. Thank you, Steve
Didn't you already post this in the Q&A and get an answer to it?? Generating numbers to the multiple of 5?[^]
Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.
-
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). :doh:Luc Pattyn [My Articles] Nil Volentibus Arduum
-
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... :laugh:
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? :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
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 :-D
Never underestimate the power of human stupidity RAH
-
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). :doh:Luc Pattyn [My Articles] Nil Volentibus Arduum
-
Generate a random integer in [2000, 19999] and multiply it by 5. The result will always be in [10000, 99999] (ie 5 decimal digits) and be divisible by 5 (by construction)
int yourNumber = 5 * rand.Next(2000, 20000); // remember the max-bound is exclusive
if (yourNumber % 5 != 0)
Console.WriteLine("the universe is wrong");And make sure you reuse a single instance of
Random
, if you create new ones the result won't be random. [/spoon feeding]David1987 wrote:
And make sure you reuse a single instance of
Random
,How exactly do I ensure that I am doing this? I am using rand a number of times, and although I get different values, it does appear that they are very simular. Regards, Stephen
-
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.
-
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
99335However, 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
All integers evenly divisible by 5 must end in either 5 or 0 when expressed in base 10. This is basic math.
Software Zen:
delete this;
-
Hi. First, how would I create a random number, and then add the last digit, so that it is divisable by 5? the number should always be 5 digits long. Second, how do I check it, I think I need to do something like...
if (int x MOD 5 ==0)
Or something like that. The first step is the most important though. Thank you, Steve
Is this a joke question? Generate a four digit number and add an extra number to the end, being either 5 or 0. Then don't check it because it will be correct!!! e.g. 4678; add 5 on the end to give 46785.
-
Hi. First, how would I create a random number, and then add the last digit, so that it is divisable by 5? the number should always be 5 digits long. Second, how do I check it, I think I need to do something like...
if (int x MOD 5 ==0)
Or something like that. The first step is the most important though. Thank you, Steve
-
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
-
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
-
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
Actually, every number is divisible by 5.