How to insert source code into a latex document.

listings

First method: use listings package

Package

\usepackage{listings}

Usage

\lstset{language=c}
\lstset{caption=Some caption}
\lstset{captionpos=b} // caption at bottom, default to top
\lstinputlisting{some source code.c}

For short code:

\begin{lstlisting}
Your source code here
\end{lstlisting}