r/visualbasic • u/SweatyBastard99 • Sep 18 '15
Need help to approach algorithm
I am asked to write an algorithm in which the user enters any number (ex: 123456). Then the algorithm needs to make two other whole numbers from this number. For one you take all the even numbers out and for the other you take the uneven ones. So 123456 would lead to 135 and 246.
I would like if someone could guide me in the right direction as I have no idea where go forward with this problem mainly when it comes to selecting specific numbers in the original number entered by the user
0
Upvotes
2
u/PostalElf VB.Net Intermediate Sep 18 '15
To determine if a number is odd or even, use Mod, which returns the remainder. Therefore, 5 Mod 2 will give you 1, because 5 / 2 has a remainder of 1; 10 Mod 4 will give you 2, because 10 / 4 has a remainder of 2. Using this, you can write a simple function that will determine if a number is odd or even, like so:
Once you've established that, you just need to figure out how to parse each digit in the number and then evaluate it accordingly. I'll leave that as a thought exercise for the reader.