Algorithm has 3 sections :
Header : Algorithm Name.Declaration : A description of variable and their types.
Algorithm body's : A Sequenc of algorithm steps.
----------------
----------------
----------------
Halt
Example 1 : Algorithm for adding two numbers
- Start
- [ Obtain input values ]
Read (A, B) - [ Add numbers and store the result ]
C <- A + B - [ Print result ]
Write (c) - Stop
Example 2 : Algorithm for finding xn for given x and n
- Start
- [ Obtain input value ]
Read (x, n) - [ initialize result so far ]
result -> x - [ initialize loop counter ]
i -> 1 - [ Print result ]
repeat thru step 7 while i < n - [ Recomputed result so far ]
result <- result * x - ( increment counter )
i <- i + 1 - ( Display result )
Write (x, n, result) - ( finish )
- Halt
What are the Notations we will use to write an Algorithm?
Notations :Beginning or Ending : Start, Stop
Input :Read( variable )
Example : Read( var1, var2 )
Output : Write ("Test to be displayed", variables)
Example : Write("Learning C", var1, var2)
Comment : [ Information ]
Operator :
&&, >, <, +, -, *, /, %, and, or, not
0 Comments