Computer Science, asked by shh2120550muskan, 2 months ago

is recursion is the concept of a function ? explain with the help of programs . write the difference between actual and formal parameters with the help of cell by value parameters passing technique​

Answers

Answered by rockwalker21
0

Answer:

Recursion is the process of defining a problem (or the solution to a problem) in terms of (a simpler version of) itself.

For example, we can define the operation "find your way home" as:

If you are at home, stop moving.

Take one step toward home.

"find your way home".

Here the solution to finding your way home is two steps (three steps). First, we don't go home if we are already home. Secondly, we do a very simple action that makes our situation simpler to solve. Finally, we redo the entire algorithm.

Ex. program

// Factorial of n = 1*2*3*...*n

#include <iostream>

using namespace std;

int factorial(int);

int main() {

int n, result;

cout << "Enter a non-negative number: ";

cin >> n;

result = factorial(n);

cout << "Factorial of " << n << " = " << result;

return 0;

}

int factorial(int n) {

if (n > 1) {

return n * factorial(n - 1);

} else {

return 1;

}

}

The key difference between Acutal Parameters and Formal Parameters is that Actual Parameters are the values that are passed to the function when it is invoked while Formal Parameters are the variables defined by the function that receives values when the function is called.

ex of actual parameter:-

def addition(x, y) {

addition = x+y

print(f”{addition}”)

}

addition(2, 3)

addition(4, 5)

ex of formal parameter:-

<def keyword> <method name> (formal parameters):

# set of statements to be executed

Similar questions