Yoga Vignesshwar Venkatsan wrote:Is this the correct... approach
Well, you could run your program though various inputs and verify output(s) with your own
manual calculations in your head. See if you could arrive at some conclusions yourself first.
When testing, try to test not just what one would call
'habitual' inputs, but also some less expected, i.e. 1, 0; -3;
See what you get.
Yoga Vignesshwar Venkatsan wrote:Is this the... efficient approach
There is no definite answer to that. More like, is this efficient enough to your needs? Likely yes. There are some other ways of doing this, I think more efficient, but certainly less known and understood. i.e. use condition
if ((num & 1) == 0). Try to research why.