0% found this document useful (0 votes)
5 views

Algorithm

Uploaded by

Sri Hari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Algorithm

Uploaded by

Sri Hari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

ALGORITHM

PSEUDOCODE
& FLOWCHART
Pseudocode
Definition: Pseudocode consists of statements which are combination of English and c language that can be easily
translated into program.

• Generally pseudo code is a restatement of a problem as a list of steps in English like format that describes what
must be done to solve it.

• It is used at one stage of the development process and can be refined , made more precise gradually.

• For every problem to write Pseudocode, should answer the following :

a. what exactly the program expected to do?

b. what answers/outputs will be printed?

c. how can the problem be translated from English to C?

d. if the problem is too hard/big to translate directly ,is it possible to break the problem into simpler steps which
can be translated more easily.
Example : Pseudocode for computing the area of a
circle for a given radius.

step 1: start

step 2: take input “r”

step 3: A=3.141*r*r

Step 4: display A

Step 5: stop
Algorithm

• An algorithm is a step by step method of solving a problem.


It is commonly used for data processing, calculation and
other related computer and mathematical operations.

• Algorithms are generally created independent of


underlying languages, i.e. an algorithm can be
implemented in more than one programming language
Characteristics of an Algorithm

• Not all procedures can be called an algorithm. An algorithm should have the following

• Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases),
and their inputs/outputs should be clear and must lead to only one meaning.

• Input − An algorithm should have 0 or more well-defined inputs.

• Output − An algorithm should have 1 or more well-defined outputs, and should match the
desired output.

• Finiteness − Algorithms must terminate after a finite number of steps.

• Feasibility − Should be feasible with the available resources.

• Independent − An algorithm should have step-by-step directions, which should be


independent of any programming code.
• Example : algorithm for computing the area of a
circle for a given radius.

Step 1: [start] Begin


Step 2: [take input for radius]
Input r
Step 3: [compute area “A”] A=3.141*r*r
Step 4: [display result]
Print “A”
Step 5: [stop]
End
Examples of Algorithm and Pseudo
code
Write a pseudocode and algorithm to compute sum and average of any three numbers.

Algorithm :

Pseudocode : Step 1: [Begin]


start
Step 1: start Step 2: [read any three numbers]
Step 2: take 3 values a, b and c Input a,b,c
Step 3: [compute sum S]
Step 3: s=a+b+c S=a+b+c
Step 4: display/print s Step 4: [display S]
Print S
Step 5: avg= (a+b+c)/3 Step 5: [compute average ]
Step 6: display/print avg avg=(a+b+c)/3
Step 6: [display avg]
step 5: stop Print avg
Step 7:[ End]
stop
Write a Pseudocode and algorithm to compute the circumference/perimeter for
the given radius.
Algorithm :

Pseudocode: Step 1: [start] Begin

Step 2: [read value for radius]


Step 1: start
Input “r”
Step 2: take input “r”
Step 3: [compute perimeter “C”]
Step 3: C=2*3.141*r
C=2*3.141*r
Step 4: display “C” Step 4: [display result] Print “C”

Step 5: stop Step 5:[stop]

End
Write a Pseudocode and algorithm to compute the area of circle for the given
radius.

Algorithm :

Step 1: [start]
Pseudocode: Begin

Step 1: start Step 2: [read value for radius]


Input “r”
Step 2: take input “r”
Step 3: [compute area]
Step 3: A=3.14*r*r A=3.14*r*r

Step 4: display “A” Step 4: [display result]


Print “A”
Step 5: stop
Step 5:[stop]
End
Write pseudocode and algorithm to compute an area of rectangle

Algorithm :
pseudocode : Step 1: [start]

Step 1: start Begin


Step 2: [read length and breadth]
Step 2: take input l,b
Input l,b

Step 3: A=l*b Step 3: [compute A]


A=l*b
Step 4: Print/display A
Step 4: [display result]

Step 5: stop Print A


Step 5:[stop]
End
Write pseudocode and algorithm to compute an perimeter of rectangle

Algorithm :
pseudocode : Step 1: [start]
Begin
Step 1: start Step 2: [read length and breadth]

Step 2: take input l,b Input l,b

Step 3: [compute Perimeter]


Step 3: Perimeter=2*(l+b)
Perimeter=2*(l+b) or
or Perimeter=2*l+2*b
Perimeter=2*l+2*b

Step 4: Print/display Step 4: [display result]

Perimeter Print Perimeter


Step 5:[stop]
Step 5: stop
End
Flowchart

You might also like