While18. An integer N (> 0) is given. Using the integer division and taking the remainder of the division operations, find the number and the sum of its digits.

Solution in Python 3:

import random

N = random.randrange(1,10000000)
print("N = ",N)
q = N
i = 0
s = 0
while q >= 1:
i += 1
r = q % 10
s += r
print(i," - ",r," - ",s)
q = int(q/10)

print("Number of digits:",i)
print("Sum of digits:",s)