SZanlongo
3/5/2018 - 2:11 PM

Pseudocode Algorithm

How to format a pseudocode algorithm

From: https://tex.stackexchange.com/q/204592

\documentclass{article}
\usepackage{amsmath}
\usepackage[linesnumbered,ruled]{algorithm2e}

\begin{document}
\begin{algorithm}
    \SetKwInOut{Input}{Input}
    \SetKwInOut{Output}{Output}

    \underline{function Euclid} $(a,b)$\;
    \Input{Two nonnegative integers $a$ and $b$}
    \Output{$\gcd(a,b)$}
    \eIf{$b=0$}
      {
        return $a$\;
      }
      {
        return Euclid$(b,a\mod b)$\;
      }
    \caption{Euclid's algorithm for finding the greatest common divisor of two nonnegative integers}
\end{algorithm}
\end{document}