As mentioned by Marco Daniel in his answer, the LTXexample environment from the showexpl package easily allows you to display source code beside the output that that produces. Here is an example:

Usually the LTXexample environment is used to display the LaTeX source code and the associated output:

Code:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{showexpl}
\lstdefinestyle{ListingSample}{
basicstyle=\small\ttfamily,
numbers=none,
keywordstyle=\color{blue}\bfseries,
morekeywords={begin,end,for,maxint,to,do},
pos=l,
}
\lstdefinestyle{myLatexStyle}{
language=TeX,
basicstyle=\small\ttfamily,
numbers=none,
backgroundcolor=\color{yellow},
numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=5pt,
commentstyle=\color{red},
showstringspaces=false,
keywordstyle=\color{blue}\bfseries,
pos=l,
}
\begin{document}
\begin{LTXexample}[style=ListingSample]
\begin{lstlisting}
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{lstlisting}
\end{LTXexample}
\begin{LTXexample}[style=myLatexStyle]
\newcommand{\Command}[1]{%
\texttt{\textbackslash#1}%
}%
Inline math is specified within
a pair of \$ as in $E = mc^2$.
Display math uses \Command{[}
and \Command{]}.
For example: \[ E = mc^2 \]
\end{LTXexample}
\end{document}