Asp. Net recursive method for factorial solution-practical skills

Source: Internet
Author: User
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.

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.