Example

Example : 1

An algorithm to find the radius of a circle, given the circumference.

Step 1

:

Input C

[ input circumference of the circle ]

Step 2

:

radius ← C / (2 * PI )

[ compute radius of the circle]

Step 3

:

Output radius

[ display output]

Step 4

:

Stop

Example 2 :

An algorithm to find the area of a rectangle

Step 1

:

Input L

[input the length of the rectangle]

Step 2

:

Input B

[input the breadth of a rectangle]

Step 3

:

Area ← L * B

[ compute the area of a rectangle ]

Step 4

:

Output Area

[Display the area]

Step 5

:

Stop

Example 3:

Algorithm to find the total and average of the marks in 5 subjects when register number, name and marks in 5 subjects are input.

Step 1

:

Initialise Total and avg to 0.

Step 2

:

Input Regno

[input Register number of student]

Step 3

:

Input Name

[input Name of the student ]

Step 4

:

Input Eng

[Input marks in English – subject 1]

Step 5

:

Input Hindi

[Input marks in Hindi – subject 2]

Step 6

:

Input Phy

[Input marks in Physics – subject 3]

Step7

:

Input Chem

[Input marks in Chemistry – subject 4]

Step 8

:

Input Stat

[Input marks in Statistics – subject 5]

Step 9

:

Total ← Eng + Hindi + Phy + Chem + Stat

[ Compute the total of all subjects ]

Step 10

:

Avg ← Tot / 5

[compute average marks]

Step 11

:

Output Total

[display total]

Step 12

:

Output Avg

[display average]

Step 13

:

stop

Example 4 :

Algorithm to find whether a number input is positive , negative or zero.

Step 1 : Input N [ input a number n]

Step 2 : Check whether N is greater than zero, if yes output N is ‘positive’, goto step 5.

Step 3 : Check whether N is less than zero, if yes output N is ‘negative’, goto step 5.

Step 4 : Output N is ‘zero’

Step 5 : Stop

Example 5 :

Algorithm to find the largest of 2 numbers.

Step 1 : Input M, N [input 2 numbers M and N]

Step 2 : Is M greater than N, if yes output M “ is larger of ” N goto Step 4.

Step 3 : Output N “is larger than ” M

Step 4 : Stop.

Last modified: Tuesday, 8 November 2011, 6:18 AM