Page 70 - Digicode_AI_class_8
P. 70

You  can  make  a  function  named  VolumeOfCuboid  which  takes  parameters  L, B and  H.  Now  the
            function will look like:
            VolumeOfCuboid (L, B, H)

            {
            return L * B * H

            }
            You only need to provide the value of:
            •  Length (L)

            •  Breadth (B)
            •  Height (H)
            Thus, the variables accepted by a function to perform the set of tasks defined in its body are called
            function parameters.

            Returning Value from a Function

            The main purpose of using functions is to get rid of the repetitive block of code. So, when an operation
            is performed inside a function it gives back a value, which can be used later in the program to get the
            results, which makes a function more useful.

            Consider  the  previous  example  in  which  you  have  calculated  the  volume  of  a  cuboid,  the
            VolumeOfCuboid did not return any value. But when the program executes, the volume of cube gets
            calculated and assigned the variable “volume” to it, then it returns a value. However, it becomes
            useless if the function doesn’t return.
            To implement return function in the volume of a cuboid.
             Step 1   The code for calculating the volume of cuboid is:















             Step 2    Click on the ‘Functions’, select ‘return’ block. Drag and place it in the function block and
                     add the variable ‘volume’ to its text area as shown below


















                 68    DigiCode AI-VIII
   65   66   67   68   69   70   71   72   73   74   75