I am new to LaTeX ... I have searched many examples of algo pseudocode for this type of code.I don't know which package to use to write this algorithm.

Please help me with the code.

enter image description here

  • Hello you can use The Listings Package : ctan.org/pkg/listings – flav Mar 6 '16 at 7:19
  • 3
    @flav: The listings package might work, but there are better ones for this particular task: algorithmic, algorithm2e etc. – user31729 Mar 6 '16 at 7:30
  • Welcome to TeX.SX! What kind of documentclass do you prefer? – user31729 Mar 6 '16 at 7:32
  • @flav can u please give me the link of code examples – Udit Kumawat Mar 6 '16 at 7:46

Here is a simple example with algorithm2e.You can find more about it in the documentation in CTAN.


\caption{An Algorithm}

\KwIn{Some input}
\KwOut{Some Output}

Do something\;
\For {$i=1$ \thinspace to 100}{
    Do something one thing\;
    $F_{i}\leftarrow F_{i} + 1$\;



Here a very simple example with perl :



\lstset{language=perl, numbers=left}
## flav
## 2003-08-05

sub usage
    my  $num_arg;

    $num_arg = $#ARGV;
    if ($num_arg)
    print "Usage: $0 name_of_program\n";

sub rl
    my  $exe;

    $exe = $ARGV[0];
    while (1)
    if (fork())
        sleep 600;




enter image description here

You will find all the doc : https://www.ctan.org/pkg/listings

But Chritan Hupfer is right there are some better package for your specific matter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.