How to find a formula for the sum up to $n$ terms of the sum $1+11+111+11111...$ using $1+2x+3x^2+4x^3...$
Hint:
$$\sum_{r=1}^n\underbrace{11\cdots11}_{r\text{ terms}}=\sum_{r=0}^nr10^{n-r}$$
$$=10^{n-1}\sum_{r=1}^nr(10^{-1})^{r-1}$$
Hint:
$$1\underbrace{11111\cdots 111}_{n-times} =\sum_{i-0}^{n-1}10^i = \frac{10^n-1}{10-1}$$ $$ \underbrace{1+11+111+11111…}_{n-times} =\sum_{j=1}^{n}\underbrace{11111\cdots 111}_{j-times} =\sum_{j=1}^{n}\sum_{i=0}^{j-1}10^i=\sum_{j=1}^{n}\sum_{i=1}^{j}10^{i+1}$$ But $$1\le i\le j\le n \Longleftrightarrow 1\le i\le n~~\text{and}~~ i\le j\le n$$
Hence (By Fubini) $$ \underbrace{1+11+111+11111…}_{n-times} =\sum_{j=1}^{n}\sum_{i=1}^{j}10^{i+1} =\sum_{i=1}^{n}\sum_{j=i}^{n}10^{i+1}\\=\sum_{i=1}^{n}(n-i+1)10^{i+1}\overset{\ell = n-i+1}{==}\sum_{\ell=1}^{n}\ell 10^{n-\ell+1}$$
That is $$\color{red}{\sum_{j=1}^{n}\underbrace{11111\cdots 111}_{j-times} = 10^{n}\sum_{\ell=1}^{n}\ell (10^{-1})^{\ell-1}}$$
$1 + 11 + 111 + .... = n + (n-1)10 + (n-2)10^2 + ....+2*10^{n-2} + 10^{n-1}$
$= 10^{n-1}(n*10^{-n} + (n-1)*10^{-n+1} + (n-2)10^{-n+2} + .....+2*10 +1)$
$= 10^{n-1}(1 + 2*\frac 1{10} + ..... + (n-2)*\frac 1{10} + (n-1))$
$= 10^{n-1}[\frac{1-\frac{1}{10}^n}{(1-\frac{1}{10})^2}-\frac{n\frac{1}{10}^n}{1-\frac{1}{10}}]$