Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

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

Open
talenz opened this issue Mar 30, 2018 · 1 comment
Open

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

talenz opened this issue Mar 30, 2018 · 1 comment

Comments

@talenz
Copy link

talenz commented Mar 30, 2018

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

\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}

@garylavayou
Copy link

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

image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants