\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[brazil]{babel}
\usepackage{tikz,fullpage}
\usepackage{listings} % exibe codigos de linguagens
\usepackage{showexpl} % exibe codigos de figuras

% Definindo novas cores
\definecolor{verdecpp}{rgb}{0,0.5,0}
\definecolor{verdejava}{rgb}{0.25,0.5,0.35}
\definecolor{jpurple}{rgb}{0.5,0,0.35}

%% para usar varias linguagens use \lstdefinestyle{}
\lstdefinestyle{LaTeX}{
  language={[LaTeX]TeX},
  basicstyle=\ttfamily\small, 
  identifierstyle=\color{black}, 
  keywordstyle=\color{blue}, 
  commentstyle=\color{red}, 
  extendedchars=true, 
  showspaces=false, 
  showstringspaces=false, 
  numbers=none,
  %numberstyle=\tiny,
  breaklines=true, 
  backgroundcolor=\color{yellow!20}, 
  breakautoindent=true, 
  captionpos=b,
  xleftmargin=0pt,
  frame=none,   %%frame=single
  rframe={},
}

\lstdefinestyle{CPP}
{
  language=C++,
  alsolanguage={[Sharp]C},
  basicstyle=\ttfamily\small, 
  keywordstyle=\color{blue}, 
  stringstyle=\color{verdecpp}, 
  commentstyle=\color{red}, 
  extendedchars=true, 
  showspaces=false, 
  showstringspaces=false, 
  numbers=left,
  numberstyle=\tiny,
  breaklines=true, 
  backgroundcolor=\color{green!10},
  breakautoindent=true, 
  captionpos=b,
  xleftmargin=0pt,
}

\lstdefinestyle{Java}
{
  language={Java},
  basicstyle=\ttfamily\small, 
  keywordstyle=\color{jpurple}\bfseries,
  stringstyle=\color{red},
  commentstyle=\color{verdejava},
  morecomment=[s][\color{blue}]{/**}{*/},
  extendedchars=true, 
  showspaces=false, 
  showstringspaces=false, 
  numbers=left,
  numberstyle=\tiny,
  breaklines=true, 
  backgroundcolor=\color{cyan!10}, 
  breakautoindent=true, 
  captionpos=b,
  xleftmargin=0pt,
  tabsize=4
}

\title{Mostrando c\'odigos no \LaTeX}
\author{\texttt{latexbr.blogspot.com.br}}
\date{}

\begin{document}
\maketitle

\section*{Código C++}

\begin{lstlisting}[style=CPP]
#include <iostream>
using namespace std;
int main()
{
    /* comentario */
    int n, i, a = 0, b = 1, F;
    cout << "Digite o numero de termos da sequencia de Fibonacci: ";
    cin >> n;
    cout << a << " " << b << " ";
    for (i = 0; i < n - 2; i++)
    {
        F = a + b;
        cout << F << " ";
        a = b;
        b = F;
    }
    cout << endl;
    return 0;
}
\end{lstlisting}

\section*{Código Java}

\begin{lstlisting}[style=Java]
/**
 * comentario
 */
public class HelloWorldApp {
    public static void main (String argv[])
    {
      // Comentario
      System.out.println("Hello World!");
    }
}
\end{lstlisting}

\newpage

\section*{Código \LaTeX}

% requer o pacote showexpl
\begin{lstlisting}[style=LaTeX]
\documentclass{article}
\usepackage{lstlisting,showexpl}
\begin{document}
 Exemplo de texto \LaTeX.
\end{document}
\end{lstlisting}

\section*{Código TikZ}

Aceita códigos PSTricks também.

% requer o pacote showexpl
\begin{LTXexample}[style=LaTeX,width=4cm]
% comentario
\centering
\begin{tikzpicture}[>=latex]
  \draw circle (1);
  \draw[->] (0,0) -- (45:1);
\end{tikzpicture}
\end{LTXexample}

\end{document}