Apologies for what may be a simple question, but I don't have a background in mathematics beyond high school.
I'm trying to work out a formula, that when given a number, say 2
, to treat this as "number of digits" and calculate the largest possible integer.
For example :
- If
2
, then largest number possible is99
- If
3
, then largest number possible is999
- If
4
, then largest number possible is9999
My quick and dirty solution (programmers hat on here), is to just count upwards from 0
to the given number, appending 9
, and returning the result, however there must be a mathematical formula that can do this in a cleaner and more efficient manner.
Thanks