A PSTricks solution:
\documentclass{article} \usepackage{pst-plot} \begin{document} % parameter \def\size{5} % positivenatural integernumber \begin{pspicture}(-\size,-\size)(\size.57,\size.62)% found manually \multido{\iA = -\size+1}{\numexpr2*\size+1}{% \multido{\iB = -\size+1}{\numexpr2*\size+1}{% \psset{linewidth = 0.5\pslinewidth, linestyle = dashed, linecolor = gray!50} \psline(-\size,\iA)(\size,\iA) \psline(\iB,-\size)(\iB,\size)}} \psaxes[labels = none]{->}(0,0)(-\size,-\size)(\size.21,\size.21)[$x$,0][$y$,90] \end{pspicture} \end{document} 
All you have to do is choose the value of \size and the drawing will be adjusted accordingly.
I've drawn the grid manually since pstricks-add's function for this makes it look wierd, I think.