Example: function recursion. To sell sheep, each village sold before the number of one hundred and One-seconds, after 7 villages left 2, asked how many sheep originally.

Source: Internet
Author: User

public int Qiuyang (int cun)
{
int sum = 0;
if (cun==7)//If the seventh village has 2 left, then the function ends
{
sum = 2;
return sum;
}
sum = (Qiuyang (cun + 1) + 1) * 2; (Number of Next village + 1) * *;
The number of this village is the number of the next village plus one then multiply by 2,
Qiuyang This function is called, we know the number of sheep in the last village.
(Qiuyang (cun + 1) This function is called, cun+1. It means the next village.
return sum;
}
static void Main (string[] args)
{
int sum = new program (). Qiuyang (1);

Console.WriteLine (sum);
Console.ReadLine ();

Example: function recursion. To sell sheep, each village sold before the number of one hundred and One-seconds, after 7 villages left 2, asked how many sheep originally.

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.