Page 42 - IT_V5.0_Class7
P. 42

Step 6:   Cut the sandwich into halves or quarters if desired.

                  Step 7:   Serve on a plate.
                  Step 8:   Stop

                  Algorithm 2: Write an algorithm for crossing the road safely.
                  Step 1:   Start
                  Step 2:   Walk to the zebra crossing or pedestrian signal.

                  Step 3:   Look left, then right, and then left again for vehicles.
                  Step 4:    Wait for the road to be clear or the signal to turn green.
                  Step 5:    Cross the road quickly but carefully.
                  Step 6:   Reach the other side safely.

                  Step 7:  Stop
                     CONTROL STRUCTURES IN AN ALGORITHM


                  Control structure is defined as an order of execution of a statement in an algorithm. There are three
                  types of control structures: sequential, selection, and repetition. Let us explore them in detail.
                  Sequential

                  This is the simplest form of control structure, where instructions are executed in a sequential
                  order, one after the other. For example, steps for calculating the percentage of any student:
                  1.  Input marks for English, Hindi, and Maths.
                  2.  Total the marks.

                  3.  Calculate the percentage.
                  4.  Display the percentage.
                  Let us write some algorithms based on sequential control structure.

                  Algorithm 3: Write an algorithm to subtract two numbers and display the result.
                  Step 1:  Start
                  Step 2:  Input num1 and num2.

                  Step 3:  Calculate Sub = num1 – num2.
                  Step 4:  Display Sub.
                  Step 5:  Stop

                  Algorithm 4: Write an algorithm to calculate the area of a rectangle and display it.
                  Step 1:  Start
                  Step 2:  Input length and width.

                  Step 3:  Calculate area = length * width
                  Step 4:  Display area.
                  Step 5:  Stop
                  Algorithm 5: Write an algorithm to convert length from meters to kilometers and display it.

                  Step 1:  Start
                  Step 2:  Input temp in Fahrenheit.


                    40    Information Technology (V5.0)-VII
   37   38   39   40   41   42   43   44   45   46   47