How do I solve $2^x + x = n$ equation for $x$? I need to solve the equation $$2^x + x = n$$ for $x$ through a programming-based method. Is this possible? If not, then what would be the most efficient way to approximate it?

As Winther answered, Newton method is probably the simplest numerical method to use.
When you look at the function $$f(x) = 2^x +x - n$$ you should notice that it is quite stiff. But, changing to $$g(x)=x \log(2)-\log(n-x)$$ makes the function quite linear.
Uisng the same case as Winther $n=10$ and starting at $x_0=0$, the iterates are $$x_1=2.903099386$$ $$x_2=2.840013526$$ $$x_3=2.839966365$$ which is the solution for $10$ significant digits.
Let us make it (apparently) more difficult with $n=10^6$ still starting at $x_0=0$; the iterates are $$x_1=19.93153981$$ which is the solution for $10$ significant digits.
In practice, you can use as a starting point the first iterate of Newton method that is to say $$x_0=\frac{\log (n)}{\frac{1}{n}+\log (2)}$$
You could have a better approximation using Halley method which leads to $$x_0=\frac{n \left(2 (n \log (2)+1)^2-\log (n)\right) \log (n)}{2 (n \log (2)+1)^3}$$ For $n=10$, this would give $x_0\approx 2.84997$.
