Design an algorithm to find average of salary

This example is little complex. You will understand it more clearly after reading the user defined data types.
Problem: Design an algorithm to find average of SALARY in an array of EMP struct containing information EMPNO, EMPNAME, and SALARY.
Input: A list employees of the type struct.
Output : Display the average of SALARY.

AVG_SALARY(LIST, SIZE)
[LIST is an array of EMP, SIZE is size of array]
SUM<-- 0
Repeat For I=1,2,3,........SIZE
SUM<--SUM +LIST[I].SALARY
[END of For I]
AVG <-- SUM / SIZE
Write :  'The average Salary is', AVG
Exit

Note : An algorithm, that perform sub-task, may be called in another algorithm. It is a better practice to divide the given problem into sub-problems ans write the individual algorithm to solve such sub-problems. Write the main algorithm to call the sub-algorithms in order to solve the main problem.




Design an algorithm to find average of salary Design an algorithm to find average of salary Reviewed by Jacob Lefore on November 07, 2014 Rating: 5

No comments