How to format a pseudocode algorithm
\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}