Front desk:
Copy Code code as follows:
<asp:textbox id= "TextBox1" runat= "Server" ></asp:TextBox>
!<asp:button id= "Button1" runat= "Server" onclick= "Button1_Click" text= "="/>
<asp:textbox id= "TextBox2" runat= "Server" ></asp:TextBox>
Background:
Copy Code code as follows:
protected void Button1_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)//where the factorial of 0 and 1 is to be considered 1, it is necessary to return 1 when data==0.
{
return 1;
}
Else
{
Return data * Jiecheng (DATA-1);
}
}
the characteristic of solving the problem by recursive algorithm:
(1) Recursion is calling itself in a procedure or function.
(2) When using a recursive strategy, there must be a definite recursive termination condition, called a recursive exit.
(3) The recursive algorithm problem solving is usually very concise, but the recursive algorithm problem-solving operation efficiency is low. Therefore, we generally do not advocate the use of recursive algorithms to design programs.
(4) in the process of recursive call system for each layer of the return point, the local amount of the stack to store. Too many recursive times cause stack overflow and so on. Therefore, we generally do not advocate the use of recursive algorithms to design programs.