How to write a pseudo code with examples

how to write a pseudocode

If you are interested to know everything about pseudo code. You are in the right place. In this post, we are going to cover what is pseudo-code and who to write pseudocode. In addition, we are also covering rules and constructs.

Being a programmer you should know what is pseudo-code and how to write pseudocode. Pseudocode is easier than writing program syntax. It also helps other programmers how the code works. Different programming languages use different functions for performing operations. But the pseudo-code uses common words that can be understood by anyone.

Check out: Best youtube channels to learn Programming

Table of Contents

What is Pseudocode

Pseudocode is a description of the algorithm or solution with step by step process. In simple terms, it is a translation of algorithms in simple understandable plain English. There is no definite syntax. Psuedo code is created for the user’s purposes and cannot be compiled or interpreted.

Using Pseudocode has many advantages. One being the readability and also there is no specific syntax, which makes it both pros and cons, Con is the acceptance.

Advantages of pseudo-code

  • Pseudo code is easier to understand. Even a non programmer can understand it since it is written in a plain english.
  • Pseudocode can be converted into any programming language with ease and less efforts.
  • The syntax and implementation does matters in pseudo code
  • Pseudo code is not based on the single programming langauge.
  • Errors are likely to occur less.
  • It is easier to explain code using pseudo code to programmers of different language.
  • Easy to implement solution using plain english.
  • More readable when compared to algorithms

The Main Constructs of Pseudocode

There are 6 main constructs used repeatedly in pseudo-code. These are also known as keywords, Which denotes a particular operation. They describe the control flow of the solution. Usually, these constructs are written in uppercase to make them stand out in the code. Below are the 6 Constructs and their uses. You should know these before writing pseudocode

1. SEQUENCE: It represents the sequence of the command which are performed sequentially

2. IF-THEN-ELSE: These are the conditional keywords that are often used in pseudo-code and programming languages. IF is mainly used to check conditions.

3. WHILE: It’s a looping construct. Which keeps looping until the condition becomes FALSE.

4. FOR: This is similar to WHILE. But a FOR LOOP loops statement is specified the number of times.

5. REPEAT-UNTIL: It is similar to FOR construct. It Repeats a certain statement or set of statements a specified number of times without worrying about other conditions.

6 CASE: It is a general form of the above conditional statement IF-THEN-ELSE

Rules for Writing Pseudocode

There are certain rules which must be followed to improve the structure and understanding of Pseudocode. However, these rules are not for functionality. They mainly deal with structure and readability to increase the understanding of code. Pseudocode is made for humans, hence it should be user understandable. Following below rules

  • Write only single statement for each line. Adding more than one tampers readibility.
  • Capatilize the intial keywords like constructs to improve readbility and understanding
  • Use indent to show flow and hirearchey
  • Keep it simple and readble as much as possible
  • Restrict the writing of pseudo code focused mainly on single language.

How to write a Pseudo code

There are multiple ways to write a pseudo code. the way is based on the individual. There is a common way of writing pseudo-code that is universally accepted. Follow the below method to writing a pseudo-code that is clean and understandable.

1. First prepare the solution and arrange the flow of control accordingly. Without proper flow control, the code will be messy.

2. Begin with the comment to tell what the program or code does. This shouldn’t be missed, Since others may find it hard to know what is this pseudo code is about. Use the common functions and restrict using a specific programming language.

3. Capitalize the Intilaize keyword such as Constructs. This will highlight the conditional and control statements.

4. Follow the appropriate indexation after the conditional statements and end it after the end of the conditional block.

5. Explain every part in detail to make sure each block is understood

6. Use END statements to denote the end.

Examples of Pseudocode

Pseudocode to add 2 numbers


This Pseudocode is for adding two numbers and displaying result

BEGIN
 
  NUMERIC a,b
  DISPLAY "ENTER THE FIRST NUMBER : "
  INPUT a
 
  DISPLAY "ENTER THE SECOND NUMBER : "
  INPUT b
 
  Compute Result=a+b
  DISPLAY Result

END

Pseudocode to Find the Area of Rectangle

Pseudocode to find the Area of Rectangle

BEGIN 
    NUMERIC Length,Breadth,Area
    DISPLAY "ENTER THE LENGTH OF RECTANGLE : "
    INPUT Length
    DISPLAY "ENTER THE BREADTH OF RECTANGLE : "
    INPUT Breadth
    Area=Length*Breadth
    DISPLAY "AREA OF RECTANGLE : " Area
END

Pseudocode to Find Area of Circle


Program to compute Area of Circle

BEGIN
    NUMERIC r, Area 
    INPUT r 
    Area=3.14*r*r 
    OUTPUT Area 
END

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Notice: ob_end_flush(): Failed to send buffer of zlib output compression (0) in /home/hackerst/public_html/wp-includes/functions.php on line 5349