Computer Science Canada Whole Number Finding? |
Author: | mattpk [ Mon Sep 21, 2009 7:52 pm ] |
Post subject: | Whole Number Finding? |
How would i check if a number is a whole number through turing? I want to make a program that finds factors for you |
Author: | Tony [ Mon Sep 21, 2009 8:14 pm ] | ||
Post subject: | RE:Whole Number Finding? | ||
Strictly speaking, you can check for
But really, you are looking for the modulo operator. |
Author: | OneOffDriveByPoster [ Mon Sep 21, 2009 8:15 pm ] |
Post subject: | Re: Whole Number Finding? |
mattpk @ Mon Sep 21, 2009 7:52 pm wrote: How would i check if a number is a whole number through turing? I want to make a program that finds factors for you It looks like you are trying trial division. Turing provides "rem" which the remainder. |
Author: | mattpk [ Mon Sep 21, 2009 8:35 pm ] |
Post subject: | RE:Whole Number Finding? |
i didnt one hundred percent understand you guys, but i was able to find out that i could do Quote: loop
if round(num / count) = num / count then factor := count put factor end if count -= 1 exit when count = 0 end loop |
Author: | Tony [ Mon Sep 21, 2009 8:45 pm ] | ||
Post subject: | RE:Whole Number Finding? | ||
|
Author: | Kharybdis [ Tue Sep 22, 2009 2:16 pm ] | ||
Post subject: | RE:Whole Number Finding? | ||
There's also a simple error check that you can do.
|
Author: | andrew. [ Tue Sep 22, 2009 4:18 pm ] |
Post subject: | RE:Whole Number Finding? |
You can do this multiple ways. One way is to round it and see if it is different. If it is, then it wasn't an integer. Another way is to do what Kharybdis said and convert the number to a string (or get it as a string) and then see if it's okay for it to be an integer (strintok). If it is, then it is an integer, otherwise it's something else. |