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?

You could either use numerical methods such as interval bisection, Newtons Method of finding roots applied to $f(x) = 2^x + x - n$, as in Winther's solution.
Secondly, you could solve this equation manually to get the solutions as $x=0$ for $n=1$ and $$x=n-\frac{W_{c}\left(2^n \ln 2\right)}{\ln 2}$$ where we let $c$ range over the integers. If you are utilising a language (Mathematica, let's say) that has the Lambert W function built in, you could simply iterate the function by running through $c \in \mathbb{Z}$.
Note:
If you're looking for real solutions, $W_0(x)$ is real for $−1/e\leq x<\infty$ and $W_{−1}(x)$ is real for $−1/e\leq x < 0$. The other branches do not have real values on $\mathbb{R}$. In this case, we have $2^n \ln 2 > 0$, so we only need $W_0$. (Thanks to Robert Israel) 
