Exercise 1: Function To Check Sum
In this exercise, you have to write a code to add integers and return their sum using the pass by value method
We'll cover the following
Problem Statement
Write a function checkSum
which
-
Takes two integers
num1
andnum2
.- pass by value method is used to pass the arguments to function.
-
Has a
check
variable whose value gets updated as explained below. -
Adds
num1
andnum2
, and checks if their sum is less than 100 in which case- it prints sum is less than 100.
- sets the value of the
check
variable to 0.
-
If sum is greater then 100
- it prints sum is greater than 100.
- sets the value of the
check
variable to 1.
-
If sum is equal to 100
- it prints sum is equal to 100
- sets the value of the
check
variable to 2.
-
At the end it will
return
the check variable.
Example
Input: 4, 80
The console should display the following:
Note: In the above case the function should set
check
to 0.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy