I am using the algorithmic package to add code in my latex documents. I came across the following issue: How to include math in the code? Simple solution:
\begin{lstlisting}[mathescape]
Thanks to http://stackoverflow.com/questions/2809836/latex-math-symbols-in-listings