Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 67 - 2607_Trackpad_Pro_5.1_flipbook_C6
P. 67

    ALGORITHM

                     Before writing a computer program to solve a problem or to perform any task, a programmer writes
                     the steps for the same. Writing a program becomes easy if the algorithm is written first. Algorithms
                     are used in our daily lives, too. For example, a recipe detailing steps to create a dish is also an
                     algorithm.
                     An  algorithm  is  a  set  of  instructions  or

                     steps  performed  in a specific  order to          Which algorithm is used by Google Maps?
                     solve a problem or to complete a task. In
                     other words, algorithms are the building blocks of computer programs that comprise a sequence
                     of operations  to be performed by the computer in a specific order to solve a problem.

                     USES OF AN ALGORITHM

                     An algorithm is mainly used for:
                       Performing data processing               Performing logical and mathematical operations
                       Manipulating data                        Searching for a particular data
                     Algorithms make decision-making more consistent and efficient.

                                WRITING AN ALGORITHM

                     The algorithm provides a step-by-step solution to the problem. Let’s write algorithms for some

                     problems.
                     MAKING A CUP OF TEA                                         CALCULATE  THE SUM OF  TWO
                     Step  1   Start.                                            NUMBERS
                     Step  2    Collect  Kettle,  Teabags, water, milk,  sugar,   Step  1   Start.
                               and cup.                                          Step  2    Read two numbers and store
                     Step  3   Boil the water in the kettle.                               them in A and B.
                     Step  4   Pour the boiling water into the cup.              Step  3   Add two numbers A and B.

                     Step  5    Add milk, sugar and put a teabag in the cup.     Step  4   Print the sum.
                     Step  6   Stir the tea, and the tea is ready.               Step  5   Stop.
                     Step  7   Stop.
                     CALCULATING THE AREA OF A CIRCLE
                     Step  1   Start.

                     Step  2    Read the radius of the circle and store it in r. (where, r is the length from the centre of
                               the circle to the edge of the circle.)
                                                                                    2
                     Step  3   Calculate the area of the circle. (where, Area = π × r (3.14 × radius × radius))
                     Step  4   Print the area.
                     Step  5   Stop.

                                                                                                 Algorithm & Flowchart  65

| 62 63 64 65 66 67 68 69 70 71 72 |