4

I am using TEXMAKER. Here is a code segment.

\usepackage{algorithmic} 
begin{algorithmic}
\FOR {$i\gets0$ to $n$} \do
    \FOR {$j \gets$0 \TO $min(i,k)$} \do 
        \IF {$j=0$ \OR $j=i$}
            \STATE $C[i,j] \gets  1$
        \ELSE
            \STATE $C[i,j] \gets  C[i-1,j-1]+C[i-1,j]$
        \ENDIF
    \ENDFOR
\ENDFOR
\RETURN C[n,k]

\end{algorithmic}
1
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – jub0bs
    Commented Mar 28, 2014 at 13:06

1 Answer 1

4

Remove the \dos, and this works fine. As a side note, use $\min(i,k)$ instead of $min(i,k)$, and (as egreg mentioned in a comment) there is a pair of $ missing from the last line of the algorithm.

\documentclass{article}
\usepackage{algorithmic} 
\begin{document}
\begin{algorithmic}
\FOR {$i\gets0$ to $n$} 
    \FOR {$j \gets$0 \TO $\min(i,k)$} 
        \IF {$j=0$ \OR $j=i$}
            \STATE $C[i,j] \gets  1$
        \ELSE
            \STATE $C[i,j] \gets  C[i-1,j-1]+C[i-1,j]$
        \ENDIF
    \ENDFOR
\ENDFOR
\RETURN $C[n,k]$
\end{algorithmic}

\end{document}

enter image description here

2
  • You're missing two $ signs in the last line.
    – egreg
    Commented Mar 28, 2014 at 14:09
  • @egreg Indeed I am, didn't notice that one. Thanks! Commented Mar 28, 2014 at 15:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .