logo CodeStepByStep logo


Language/Type: VB loops while loops parameters Mod

Write a subroutine named ShowTwos that shows the factors of 2 in a given integer. For example, the following calls should produce the following console output:

Call Output
ShowTwos(7) 7 = 7
ShowTwos(18) 18 = 2 * 9
ShowTwos(68) 68 = 2 * 2 * 17
ShowTwos(120) 120 = 2 * 2 * 2 * 15

The idea is to express the number as a product of factors of 2 and an odd number. The number 120 has 3 factors of 2 multiplied by the odd number 15. For odd numbers (e.g. 7), there are no factors of 2, so you just show the number itself. Assume that your subroutine is passed a number greater than 0.

Function: Write a VB function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.