Implemented loop and optimized printnum