What are the ways to describe an algorithm? Write down the pseudocode structures for looping and conditional statements.
Subject Algorithm Design
NU Year Set: 2.(a) Marks: 5 Year: 2009

An algorithm consists of a set of explicit and unambiguous finite steps which, when carried out for a given set of initial conditions, produce the corresponding output and terminate in finite time.

 

Initialize total to zero
Initialize counter to zero
Input the first grade
while the user has not as yet entered the sentinel
   add this grade into the running total 
   add one to the grade counter  
   input the next grade (possibly the sentinel)
endwhile

if the counter is not equal to zero
   set the average to the total divided by the counter
   print the average  
else
   print 'no grades were entered' 
endif

 

Login to post your comment.