The source code to create nested functions is given below. The given program is compiled and executed on the ubuntu 18.04 operating system successfully.
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.
Here, we defined a function AddAndSubtract() that contains the definition of two nested functions Add() and Sub(). And, we calculated the addition and subtraction of integer numbers and printed the result on the console screen.
In the main() function, we called AddAndSubtract() function with value 30, 10 to perform addition and subtraction operation.
Program/Source Code:
The source code to create nested functions 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.
Here, we defined a function AddAndSubtract() that contains the definition of two nested functions Add() and Sub(). And, we calculated the addition and subtraction of integer numbers and printed the result on the console screen.
In the main() function, we called AddAndSubtract() function with value 30, 10 to perform addition and subtraction operation.
need an explanation for this answer? contact us directly to get an explanation for this answer