(a) Define algorithm. (b) State three characteristics of an algorithm. (c) Write an algorithm for finding the average of numbers, when the sum of the number...
(a) Define algorithm. (b) State three characteristics of an algorithm. (c) Write an algorithm for finding the average of numbers, when the sum of the numbers is given.
(a) Definition of algorithm
An algorithm is a finite set of clear, step-by-step instructions for solving a particular problem, arranged in a logical order so that following the steps produces the required result.
(b) Three characteristics of an algorithm
Finiteness - it must have a definite ending after a finite number of steps.
Effectiveness with input and output - it must take input (where needed) and produce at least one output, and every step must be doable. (Being general/applicable to a class of problems is also acceptable.)
(c) Algorithm for finding the average of numbers when the sum is given
The average is the sum divided by the count of numbers, \(Average = \dfrac{Sum}{N}\).
Start.
Read the sum of the numbers, SUM.
Read the count of the numbers, N.
If N = 0, display "cannot divide by zero" and go to step 7.
An algorithm is a finite set of clear, step-by-step instructions for solving a particular problem, arranged in a logical order so that following the steps produces the required result.
(b) Three characteristics of an algorithm
Finiteness - it must have a definite ending after a finite number of steps.
Effectiveness with input and output - it must take input (where needed) and produce at least one output, and every step must be doable. (Being general/applicable to a class of problems is also acceptable.)
(c) Algorithm for finding the average of numbers when the sum is given
The average is the sum divided by the count of numbers, \(Average = \dfrac{Sum}{N}\).
Start.
Read the sum of the numbers, SUM.
Read the count of the numbers, N.
If N = 0, display "cannot divide by zero" and go to step 7.