Actually, in the first version, there are separate cases and lots of "if" statements. You could probably just use the last version if (num >= 1000 && num <= 9999) even if the number has fewer than four digits it should still work. (Some values will of course be zero).
Similarly, the second version, rather than using a loop, could use the same concept, repeating the code several times. Then instead of storing each value in "digit", you could use separate fields for hundreds, tens etc.
There are always multiple ways to approach a problem, some may be more efficient than others, but even the other ways can be useful in understanding how the thing works.