ASP. NET Recursive Method for factorial Solution

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.