Write the algorithm and draw flowcharts
for following:
To add three numbers.
Answers
An algorithm is a set of steps designed to solve a problem or accomplish a task. Algorithms are usually written in pseudocode, or a combination of your speaking language and one or more programming languages, in advance of writing a program
One of the most obvious examples of an algorithm is a recipe. It's a finite list of instructions used to perform a task. For example, if you were to follow the algorithm to create brownies from a box mix, you would follow the three to five step process written on the back of the box.
Answer:
•••●Hope it helps you dear mate ●•••
Explanation:
A flow chart is but a pictorial representation of an algorithm and is meant to depict the flow of control in a program.
The first step is to decide on an algorithm and maybe write it in the form of a pseudo code, an informal way of writing statements of a program without bothering about details of syntax.
Algorithms for the given problem:
[I]
Initialize Counter=0, Sum=0
Input integer
Add integer to Sum
Increment Counter
If Counter > 3, divide Sum by 3, Output result, stop
Else go to 2
[II]
Input Integer1, Integer2, Integer3
Average= ( Integer1+ Integer2+Integer3)/3
Output average
The second algorithm would be clumsy to find the average of a large number of inputs.
The first one can be easily generalised to handle n inputs, by introducing step 0 and modifying step 5
0. Input n
5. If Counter > n , divide Sum by n, Output result, stop
Note : There can be more ways of writing an algorithm for the problem by invoking loop control statements.
Having decided on the algorithm one can draw the flow chart following diagrammatic conventions, like using diamond boxes for decision (If), rectangles for assignment statements and conventional symbols [ ] for input and output. The control flow is to be indicated by directed arrows.