Does that work?
I think the limits of the loops need work, and that you need to consider the input=1 case, but it looks fine. ANd yer missing a ; in places. And you don't need the else. And you have a ; where you don't need one (end of the first for line).