shifujun/UESTCthesis

怎么用algorithm环境插入伪代码来表示算法呢?

Opened this issue · 1 comments

下面这样编译过不了呢?有什么办法可以插算法环境吗?

\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}
\caption{Calculate $y = x^n$}
\label{alg1}
\begin{algorithmic}
\REQUIRE $n \geq 0 \vee x \neq 0$
\ENSURE $y = x^n$
\STATE $y \gets 1$
\IF{$n < 0$}
\STATE $X \gets 1 / x$
\STATE $N \gets -n$
\ELSE
\STATE $X \gets x$
\STATE $N \gets n$
\ENDIF
\WHILE{$N \neq 0$}
\IF{$N$ is even}
\STATE $X \gets X \times X$
\STATE $N \gets N / 2$
\ELSE[$N$ is odd]
\STATE $y \gets y \times X$
\STATE $N \gets N - 1$
\ENDIF
\ENDWHILE
\end{algorithmic}
\end{algorithm}

\usepackage{algorithm,algorithmic} 没有问题,可以正常编译, @talenz

image