\documentclass{article}
\usepackage{amsmath,amsfonts}

\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}

\begin{algorithm}
\caption{A Generic Pseudocode Example}
\textbf{Input:} 
\begin{itemize}
    \item An input value $x$.
\end{itemize}

\textbf{Output:}
\begin{itemize}
    \item An output value $y$.
\end{itemize}

\textbf{Initialization:} 
\begin{itemize}
    \item Initialize a variable $z$ to 0.
\end{itemize}

\begin{algorithmic}[1]
\State $z \leftarrow 0$ \Comment{Initialization}
\If{$x$ is even}
    \State $y \leftarrow x / 2$ \Comment{Compute the result for even input}
\Else
    \State $y \leftarrow 3x + 1$ \Comment{Compute the result for odd input}
\EndIf

\For{$i$ from 1 to 10}
    \State Perform some computation with $i$
\EndFor

\While{$y$ is not equal to 1}
    \State Perform some repetitive computation
    \State $y \leftarrow y - 1$
\EndWhile

\Return $y$ \Comment{Return the final result}
\end{algorithmic}
\end{algorithm}

\end{document}

Logo

欢迎加入我们的广州开发者社区,与优秀的开发者共同成长!

更多推荐