📜  latex 如何编写算法伪代码 - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:09.588000             🧑  作者: Mango

代码示例1
% in the header:
% \usepackage{algorithm}
% \usepackage{algpseudocode}

% in the  body:
\begin{algorithm}
  \caption{Euclid’s algorithm}
  \label{euclid}
  \begin{algorithmic}[1]
    \Require $x\ge5$
    \Ensure $x\le-5$
    \Function{Euclid}{$a,b$}
      \Comment{The g.c.d. of a and b}
      \State $r\gets a\bmod b$
      \While{$r \neq 0$}
        \Comment{We have the answer if r is 0}
        \State $a\gets b$
        \State $b\gets r$
        \State $r\gets a\bmod b$
      \EndWhile
      \label{euclidendwhile}
      \State \Return{$b$}
      \Comment{The gcd is b}
    \EndFunction
  \end{algorithmic}
\end{algorithm}