The source code to create a currying function to add two numbers is given below. The given program is compiled and executed on the ubuntu 18.04 operating system successfully.
// Scala program to create a currying function
// to add two numbers
object Sample {
def main(args: Array[String]) {
var result: Int = 0;
// Function calling
result = AddNum(10, 20);
printf("Result : %d\n", result);
}
// Function definition of currying function.
def AddNum(num1: Int, num2: Int) = num1 + num2;
}
Output:
Result : 30
Explanation:
In the above program, we used an object-oriented approach to create the program. We created an object Sample, and we defined main() function. The main() function is the entry point for the program.
In this program, we defined a currying function AddNum() with two integer arguments. The AddNum() function adds two specified numbers and returns the result to the calling function.
In the main() function, we created an integer variable result, initialized with 0. Then we called the AddNum() function with values 10, 20. The AddNum() function returns the addition of arguments, which is assigned to the result variable. After that, we printed the result on the console screen.
Program/Source Code:
The source code to create a currying function to add two numbers is given below. The given program is compiled and executed on the ubuntu 18.04 operating system successfully.
Output:
Explanation:
In the above program, we used an object-oriented approach to create the program. We created an object Sample, and we defined main() function. The main() function is the entry point for the program.
In this program, we defined a currying function AddNum() with two integer arguments. The AddNum() function adds two specified numbers and returns the result to the calling function.
In the main() function, we created an integer variable result, initialized with 0. Then we called the AddNum() function with values 10, 20. The AddNum() function returns the addition of arguments, which is assigned to the result variable. After that, we printed the result on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer