Heiko's answer explained the problem with your code, how to solve it, and also how to proceed in a different style using an expandable integer loop (thanks to \numexpr).
A.Ellett's answer provides two more solutions using pgffor and pgfkeys.
DJP' answer is a method using an external tool, here Python code which is handled by the powerful Sage via sagetex.
These answers all need in one form or another some extra work, like (for the TeX ones) hiding the tabulation & in a macro, or do global definitions with \xdef, or prepare a token list register, or use various kinds of TeX conditionals.
The xintFor construct from package xinttools is an alternative (see How to iterate over a comma separated list?) which spares the trouble of this extra coding:
\documentclass{article}
\usepackage{xinttools}
\newcommand{\N}{10}
\begin{document}
% \renewcommand{\N}{<nb of cols>}
\begin{tabular}{*{\N}c}
\xintFor* #1 in {\xintSeq {1}{\N}}\do {\xintifForFirst{}{&}#1}\\
\end{tabular}
\end{document}

The \xintifForFirst{YES}{N0} test is to insert a tabulation & only in the second and next cells of the given row (here only one row). The \xintSeq macro generates an arithmetic sequence of integers (e.g {1}{2}{3}{4}). The \xintFor* #1 in iterates over its argument (its unstarred cousin \xintFor iterates over a comma separated list), letting #1 be each item of it one after the other.
The same code as above but using rather a LaTeX counter:
\documentclass{article}
\usepackage{xinttools}
\newcounter{N}
\begin{document}
\setcounter{N}{10}
\begin{tabular}{*{\value{N}}c}
\xintFor* #1 in {\xintSeq {1}{\value{N}}}\do {\xintifForFirst{}{&}#1}\\
\end{tabular}
\end{document}
Here is now a more elaborate example (as it uses two nested loops) which constructs multiplication tables: \numexpr is used for the multiplication of the row index by the column index.

Here is the code:
\documentclass{article}
\usepackage{xinttools}
\newcommand\MultTable [4]{%
% #1, #2 row indices
% #3, #4 column indices: we need #4-#3+2 columns
\begin{tabular}{*{\numexpr#4-#3+2\relax}c}
\hline
% headerline
$\times$\xintFor* ##1 in {\xintSeq {#3}{#4}}\do{&\textbf{##1}}\\
\hline
% #2-#1+1 rows, ##1=dynamic index of each row, ##2 column index
\xintFor* ##1 in {\xintSeq {#1}{#2}}\do
{\textbf{##1}
\xintFor* ##2 in {\xintSeq {#3}{#4}}\do{&\the\numexpr ##1*##2\relax}
\\
}
\hline
\end{tabular}%
% efficiency note: one could do \edef\columnindices {\xintSeq {#3}{#4}}
% before the tabular
% and use \columnindices rather \xintSeq {#3}{#4} to avoid it being
% re-computed for each row
}
\begin{document}
\begin{table}[!htbp]
\centering
\MultTable {1}{10}{1}{10}
\caption{Multiplication table}
\end{table}
\begin{table}[!htbp]
\centering
\MultTable {123}{132}{91}{98}
\caption{Multiplication table}
\end{table}
\end{document}
As we used \xintFor* inside the definition of a LaTeX user command, we needed to double the # to avoid confusion between the ##1 of the loop and the #1 being the first parameter of the command.
\tabtoksapproach very useful. – Steven B. Segletes Mar 15 '14 at 01:12datatoolorpgfplotstableto avoid any column number concerns etc. – percusse Mar 15 '14 at 01:18