Pages

Breaking News
recent

Writing Pseudo Code

Pseudo Code 
is an informal high-level description of the operating principle of a computer program or other algorithm.
It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading. Pseudo code typically omits details that are essential for machine understanding of the algorithm, such as variable declarations, system-specific code and some subroutines. The programming language is augmented with natural language description details, where convenient, or with compact mathematical notation. 

The purpose of using pseudo code is that it is easier for people to understand than conventional programming language code, and that it is an efficient and environment-independent description of the key principles of an algorithm. It is commonly used in textbooks and scientific publications that are documenting various algorithms, and also in planning of computer program development, for sketching out the structure of the program before the actual coding takes place.



Examples in Writing Pseudo Code
Fortran style pseudo code
program fizzbuzz
Do i = 1 to 100 
    set print_number to true
    If i is divisible by 3
        print "Fizz"
        set print_number to false
    If i is divisible by 5
        print "Buzz" 
        set print_number to false
    If print_number, print i
    print a newline
end do
Pascal style pseudo code
procedure fizzbuzz
For i := 1 to 100 do
    set print_number to true;
    If i is divisible by 3 then
        print "Fizz";
        set print_number to false;
    If i is divisible by 5 then
        print "Buzz";
        set print_number to false;
    If print_number, print i;
    print a newline;
end
C style pseudo code:
void function fizzbuzz {
 For (i = 1; i <= 100; i++) {
    set print_number to true;
    If i is divisible by 3
        print "Fizz";
        set print_number to false;
    If i is divisible by 5
        print "Buzz";
        set print_number to false;
    If print_number, print i;
    print a newline;
 }
}
Basic style pseudo code
Sub fizzbuzz()
For i = 1 to 100
    print_number = True
    If i is divisible by 3 Then
        Print "Fizz"
        print_number = False
    End If
    If i is divisible by 5 Then
        Print "Buzz"
        print_number = False
    End If
    If print_number = True Then print i
    Print a newline
Next i
End Sub
Source: https://en.wikipedia.org/wiki/Pseudocode

No comments:

Post a Comment

Powered by Blogger.