You are on page 1of 13

SUBJECT CODE

TYPE THE SUBJECT NAME HERE

UNIT NO 1
INTRODUCTION TO PROGRAMMING AND
ALGORITHMS FOR PROBLEM SOLVING

1.4 Pseudo code

I I

20ESCS101
Problem Solving and Programming in C
(Common to ALL Departments)
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )

Pseudocode

❖ Pseudocode is a combination of two words Pseudo and Code.’Pseudo’ means imitation


and ‘code’ refer to instruction written in the programming language.
❖ Pseudo code is not a real programming language.It is the generic way of describing an
algorithm without using any specific programming language-related notations.
❖ Purpose- to define the procedural logic of an algorithm in a simple, easy-to- understand
for its readers.
❖ Consists of natural language-like statements that precisely describe the steps of an
algorithm or program.
❖ Pseudo code cannot be compiled and executed and there are no real formatting or
syntax rules for writing pseudo codes.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
101

Features of Pseudocode

1. It uses plain English statements


2. It emphasizes on the design of the computer program
3. Focuses on the logic of the algorithm or program
4. It uses Structured English
5. Avoids language-specific elements
6. It is detailed and readable to draw an inference
7. It enables the programmers to concentrate on the algorithms.
8. Free of syntactical complications of programming language.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )

Preparing a pseudo code

1. Pseudo code is written using structured English.


2. In a pseudo code, some terms are commonly used to represent the various actions.
3. For example, for inputting data the terms may be (INPUT,GET, READ,OBTAIN), for
outputting data ( OUTPUT, PRINT, DISPLAY), for calculations ( COMPUTE,
CALCULATE,DETERMINE), for incrementing ( INCREMENT), initialization-
INITIALIZE,SET.
4. ADD, SUBTRACT used for addition and subtraction
5. For conditional statements uses terms like IF, ELSE, ENDIF and looping
statements like WHILE, DO WHILE etc.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Pseudo code Examples
Major constructions in pseudo code structures are sequence and
selection(decision). sequence indicates the continuous flow of the program,whereas
selection uses logical comparison or conditional check for making decisions.

Example:
IF(condition) THEN
List of Actions
ELSE
List of different Actions
END IF
Example: pseudo code for Multiplying two numbers
READ a,b
COMPUTE C=a*b
PRINT C
STOP
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )

Example: pseudo code for greatest of three numbers

BEGIN

READ a,b,c

IF (a>b) and (a>c) THEN

WRITE a is big

ELSE IF (B>C) THEN

WRITE b is big

ELSE

WRITE c is big

END IF

END
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )

Example: find sum of first 100 integers

BEGIN

INITIALIZE SUM to zero

INITIALIZE I to zero

DO WHILE (I <100)

INCREMENT I

ADD I to SUM and store in SUM

END DO WHILE

PRINT SUM

STOP
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )

Example: Pseudocode to Calculate Area and Perimeter of Rectangle

BEGIN

NUMBER b1,b2,area,perimeter

INPUT b1

UNPUT b2

area=b1*b2

perimeter=2*(b1+b2)

OUTPUT area

OUTPUT perimeter

END
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )

Example: pseudo code to Print Numbers from 1 to 100

BEGIN

NUMBER counter

FOR counter = 1 TO 100 STEP 1 DO

OUTPUT counter

ENDFOR

END
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )

Example: pseudocode to find sum and average of given two numbers.

BEGIN
WRITE “Please enter two numbers to add”
READ num1
READ num2
COMPUTE Sum = num1+num2
COMPUTE Avg = Sum/2
WRITE Sum, Avg
END
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )

Advantages of Pseudo code

1. Since,it is language independent,it can be used by most


programmers
2. It is easier to develop the program from pseudo code than with a
flowchart
3. It is easier to translate to the programming language
4. Its simple structure and readability makes it easier to modify as
well

Disadvantages of Pseudo code

5. It does not provide the visual representation of the program logic


6. There are no accepted standards for writing pseudo code
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )

VIDEO LINK

1. https://www.youtube.com/watch?v=preyTbKXDoQ
2. https://www.youtube.com/watch?v=6fHRtZC_kXU
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )

THANK YOU

You might also like