Use a vector.
"Without using an array" generally means "without storing all of the numbers", which means vector is out too. But even if you could store all of the numbers, doing so would be stupid because it's trivial to write a linear algorithm without wasting memory like that.