latex编写伪代码

使用algorithmicx包

 

\begin{algorithm}
  \caption{Sum of integers from 1 to n.}
    \begin{algorithmic}[1]
      \Procedure {Sum}{$n$}
        \State $sum \gets 0  \hfill \triangleright {\rm \ Initialization}$
        \For{$i \gets 1,n$}
          \State $sum \gets sum + i$        
        \EndFor
        \State \Return{$sum$} $ \hfill \triangleright {\rm \ Return}$
      \EndProcedure
    \end{algorithmic}
\end{algorithm}

 

结果如下:

 

 

 

posted @ 2021-09-18 19:24  kafuuchino  阅读(447)  评论(0编辑  收藏  举报