find and solve ||
Please wait.....

Welcome back.

Before Read Terms of use

Writing Pseudocode: Algorithms & Examples

An algorithm, as stated earlier, is a series of instructions written in any language spoken by human beings, such as English. An algorithm describes a way to perform a particular programming task. Generally, these instructions are written in steps, where each step performs some task. Let's proceed to write an algorithm for our program that displays registration information of the students in an educational institute:

1. Initialize New_Reg to 'Y'
2. Initialize No_Stud_A to 0
3. Initialize No_Stud_B to 0
4. Initialize No_Stud_C to 0
5. Input Course_Code
6. Check the Course_Code. If it is A, the add 1 to No_Stud_A; otherwise, move to Step 7
7. If Course_Code is B, then add 1 to No_Stud_B; otherwise, move to Step 8
8. If Course_Code is C, then add 1 to No_Stud_C, 
9. Input New_Reg
10. If New_Reg is 'Y' then repeat steps 5 to 9; otherwise, move to Step 11
11. Print the total number of students registered in each course, that is, No_Stud_A, No_Stud_B, and No_Stud_C


Pseudocode is a structured of English phrases that are used to describe the algorithms. It focuses on the logic of the algorithm and does not have any programming language specific keywords. Listing 1.3 shows the pseudocode for our program that displays registration information of the students of an educational institute:

Listing 1.3: Showing the Pseudocode for the Registration Problem

Initialize New_Reg to 'Y'
Initialize No_Stud_A to 0
Initialize No_Stud_B to 0
Initialize No_Stud_C to 0
While (Value of New_Reg is 'Y')
Course_Code = Get the coursecode from the user
If Course_Code = 'A' then
No_Stud_A = No_Stud_A + 1
If Course_Code = 'B' then
No_Stud_B = No_Stud_B + 1
If Course_Code = 'C' then
No_Stud_C = No_Stud_C + 1
New_Reg = Get the character from the user
Print No_Stud_A
Print No_Stud_B
Print No_Stud_C

In Listing 1.3, the variable, New_Reg is initialized, to 'Y' and each of the variables, No_Stud_A, No_Stud_B, and No_Stud_C, to 0. Then a While loop is used, which is executed repeatedly till the value of New_Reg is 'Y'. As New_Reg is initialized to 'Y' in the beginning; therefore, the While loop will be executed at least once. Inside the While loop, course code is taken as input from the user and depending upon the course code entered, the number of students registered for the respective course is increased by one. Then,a character specifying whether or not more students need to be registered is taken as input. Finally, the number of students registered for each course is printed on the screen 

Sundar  Neupane

Sundar Neupane

I like working on projects with a team that cares about creating beautiful and usable interfaces.


Report Response