The sum of the numbers from 0 to n is easy to compute with the formula n(n+1)/2. That is, 0+1+2+⋯+n=n(n+1)/2.
This problem is a little harder. What is the sum of the digits that appear in the sequence [0,1,…,n]?
Write a program that computes the sum of every digit seen while counting from 0 to n.
For n=15 you add up the digits appearing in the sequence [0,1,2,…,14,15]. The result is 1+2+3+4+5+6+7+8+9+1+0+1+1+1+2+1+3+1+4+1+5=66.