Week13_Functions_Call_by_Value
Week13_Functions_Call_by_Value
Call-by-Value
Scope of Variables
Asst. Prof. Dr. Damla TOPALLI,
Atilim University
Call-by-value
CMPE113- 2020-21 Spring
Example-3
• Write two functions which receives a radius of type double then: find_area
calculates and returns the area and find_circum returns the circumference.
Example-3
• Write two functions which receives a radius of type double then: find_area
calculates and returns the area and find_circum returns the circumference.
Call-by-value
SAMPLE RUN
Enter an integer:34564
Sum of digits:22
Example-4
• Write a function which receives an integer number n as a parameter, then calculates and returns
the sum of digits of that number.
SAMPLE RUN
Enter an integer:34564
Sum of digits:22
Example-5
• Write four functions to perform 4 basic mathematical operations: add, subtract, multiply and
divide.
• add function receives two integer parameters, computes and returns the sum of two
numbers.
• subtract function receives two integer parameters, computes and returns the difference of
two numbers.
• multiply function receives two integer parameters, computes and returns the product of two
numbers.
• divide function receives two integer parameters, computes and outputs the result. Do not
forget to check division by zero!
• In the main program, create a menu and continue until user wants to exit.
Example-5
SAMPLE RUN
Menu Menu
1.Add 1.Add
2.Subtract 2.Subtract
3.Multiply 3.Multiply
4.Divide 4.Divide
5.Exit 5.Exit
SAMPLE RUN:
Example-6
Scope of Variables
Inside a function or a block which is called local variables.