Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+16 votes

What would be a good strategy to separate the digits from the integer and check if it is even or odd?

asked in CSC211_Winter2018 by (1 point)

2 Answers

+10 votes

Find the remainder of the numbers after dividing by 10. Also, check whether if
the remainder % 2 == 0 or not to see if it is even or odd.

answered by (1 point)
+7 votes

num % 10 will help you get the "ones" digit.

num / 10 will remove the "ones" digit to be able to test the next digit.

For example

256 % 10 = 6
then 256 / 10 = 25

So now using the 25,
25%10 = 5
then 25 / 10 = 2

answered by (1 point)
...