Front-end:
Copy codeThe Code is as follows: <asp: TextBox ID = "TextBox1" runat = "server"> </asp: TextBox>
! <Asp: Button ID = "Button1" runat = "server" onclick = "button#click" Text = "="/>
<Asp: TextBox ID = "TextBox2" runat = "server"> </asp: TextBox>
Background:Copy codeThe Code is as follows: protected void button#click (object sender, EventArgs e)
{
Int data = Convert. ToInt32 (this. TextBox1.Text. Trim (); // data is an integer greater than or equal to 0.
This. TextBox2.Text = jieCheng (data). ToString ();
}
Private static int jieCheng (int data)
{
If (data = 0) // here we need to consider that the factorial values of 0 and 1 are both 1, so 1 is returned when data = 0.
{
Return 1;
}
Else
{
Return data * jieCheng (data-1 );
}
}
Features of Recursive Algorithms for solving problems:
(1) recursion is to call itself in a process or function.
(2) When using a recursive policy, there must be a clear recursive termination condition called the recursive exit.
(3) recursive algorithms are usually simple in solving problems, but they are less efficient in solving problems. Therefore, recursive algorithms are generally not recommended for programming.
(4) In the process of recursive calling, the system opens a stack for storing the return points and local volumes of each layer. Too many recursion times may cause stack overflow. Therefore, recursive algorithms are generally not recommended for programming.