Computer Science Canada Checking individual digits in an integer |
Author: | lemoe [ Tue Feb 07, 2012 9:03 pm ] |
Post subject: | Checking individual digits in an integer |
My Problem is... I have to write a program that checks whether a number is the same when rotated 180 degrees. I don't need help with the coding, I would just like some assistance with understanding a command to do this. Is there a command that checks the character or digit at a specified location in an integer? eg.) What is the third digit of integer 1863? Thanks in advance. I am using Turing 4.0.5. |
Author: | mirhagk [ Tue Feb 07, 2012 9:20 pm ] |
Post subject: | RE:Checking individual digits in an integer |
Well an easy way would be turning it into a string, and then indexing the string. |
Author: | crossley7 [ Tue Feb 07, 2012 10:47 pm ] |
Post subject: | RE:Checking individual digits in an integer |
a way to do it without converting to a string is integer division then mod by 10. Look up the commands div and mod and think about how exactly you could do that |
Author: | lemoe [ Wed Feb 08, 2012 7:37 am ] |
Post subject: | RE:Checking individual digits in an integer |
Thanks |
Author: | mirhagk [ Wed Feb 08, 2012 10:22 am ] |
Post subject: | RE:Checking individual digits in an integer |
crossley's way it probably the better one, but just wanted to let you know there was multiple ways. |