Please look at the contents page for this forum, where it says
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
It doesn't help anybody to be given a complete solution; nobody learns like this. I have therefore removed your solution and the forum software records it somewhere.
As I mentioned earlier, your solution doesn's handle zero.
Please always indent code correctly and don't double‑space it. When you have done that, the code button will make the code look better still, as above. Please also put spaces around your operators; you only got because you didn't space the code out enough.
"To do good, you actually have to do something." -- Yvon Chouinard