Spiro - consider the line of code
if remainder == 0 && remainder == 9
Your remainder cannot be both 0 and 9...it should be one or the other. Try changing this to
if remainder == 0 || remainder == 9
to see what happens. Also, I think that if the remainder is zero or nine then this is telling you that your right-most digit is either zero or nine. If this is true, then you want to consider the next right-most digit which I think that you are trying to obtain with the line
M = floor(M/10);
So you want reduce your M if and only if the remainder is 0 or 9. If the remainder is something else, then you want to "start again" and so increment cnt and then obtain a new M.
Also, you may want to initialize cnt to zero (instead of one) to handle the case where the input is 9 (no reason to consider multiples of this number).
