1.5. Pseudo codes - notations, examples, advantages and limitations.

1.5 PSEUDO CODES - NOTATIONS, EXAMPLES, ADVANTAGES AND LIMITATIONS.

·       An algorithm is a well-defined sequence of steps that provides a solution to the problem, whereas a pseudo code is one of the methods that can be used to represent an algorithm.

·       It is a compact and informal high-level description of the program. It is a simpler version of language code in plain English before it is implemented in a specific programming language.

1.5.1 Notations

·       Pseudo code does not have strict syntax, but some of the most widely recognized are:

·       INPUT – indicates a user gives input to program

·       OUTPUT – indicates that an output will be generated on the screen.

·       WHILE – it is used for loop with condition in the beginning

1.5.2 Examples

Example1 Write a Pseudocode to check number is positive or negative.

            1 Start

            2 Read number

            3 If number >0 then Print “number is positive”

                    else if number <0 then Print “number is negative

                            else Print “number is Zero”

            4 Stop

Example 2 Write a Pseudocode for finding the average of N numbers

            1 Start

            2 Read the value of N

            3 Initialize sum=0

            4 while N>0

                        a) Read number

                        b) sum=sum+number

                        c) N=N-1

            5 Average= sum/N

            6 Print Average

            7 Stop

Example 3Write a Pseudocode to find out addition of first 20 numbers and print it.

            1 Initialize n = 20

            2 Initialize   i=1

            3 sum=0

            4 While (i <=n) do

                        a) sum= sum+i

                        b) i= i+1

            5 print sum

            6 Stop

Example 4   Write a Pseudocode to find out factorial of a integer

            1 Read number

            2 Initialize factorial=1

            3 Repeat

                        a) factorial= factorial * number

                        b) number= number - 1

                Until (Number>0)

            4 Print factorial

Example 5   Write a Pseudocode to generate Fibonacci series of n numbers

                        1, 2, 3,5,8,13,21………. up to n

            1 Read n

            2 f1=1

            3 f2=2

            4 Print f1, f2

            5 Initialize count=3

            6 While count < =n do

                        a)f3=f1+f2

                        b)Print f3

                        c)count= count+1

            7 Stop

1.5.3 Advantages and Limitations of Pseudo Codes

Advantages Pseudo Codes

1 Pseudocode is code which is written in English to solve a particular problem so it is easily written.

2 Easily understood by anyone.

3 In case of there is change in logic you want modify in the Pseudo Code then it is easy to modify compared to Flowchart.

4 For writing Pseudocode any word processor can be used

5 Pseudocode implements the structure concepts.

6 Once the Pseudocode is written then it can be easily converted into a program.

7 While writing Pseudocode we can concentrate only on solving of the program rather syntax

8 Pseudocode is the same for any language.

Limitations Pseudo Codes

1 Sometimes Pseudocode is difficult in understanding the logic of a program.

2 Difficult to understand the flow of control as compared to Flowchart.

3 There is no fixed syntax to write Pseudocode

4 It is not executable

5 If Pseudocode is wrong then a program based on this will also be wrong.

6 Errors cannot be easily detected.

0 Comments:

Post a Comment