代碼:
\begin{algorithm}[t]
\caption{algorithm caption} %算法的名字
\hspace*{0.02in} {\bf Input:} %算法的輸入, \hspace*{0.02in}用來控制位置,同時利用 \\ 進行換行
input parameters A, B, C\\
\hspace*{0.02in} {\bf Output:} %算法的結果輸出
output result
\begin{algorithmic}[1]
\State some description % \State 後寫一般語句
\For{condition} % For 語句,需要和EndFor對應
\State ...
\If{condition} % If 語句,需要和EndIf對應
\State ...
\Else
\State ...
\EndIf
\EndFor
\While{condition} % While語句,需要和EndWhile對應
\State ...
\EndWhile
\State \Return result
\end{algorithmic}
\end{algorithm}
效果: