Given number n. Find the n digit numbers.

51 Views Asked by At

For eg; if n = 2,

Then the output should be 10,11,...99 // (i.e) 10 to 99

if n = 3,

Output: 100,101...999 //note the 3 digit numbers are returned. The range would be 100 to 999.

How can i achieve this. Is there any formula to get the range.

1

There are 1 best solutions below

2
On BEST ANSWER

The range $[a, b] \cap \mathbb N$ of numbers with $n$ digits is determined by $$\begin{align*} a &= 10^{n - 1}\\ b &= 10^n - 1. \end{align*}$$