Recursive function--catching sheep

Source: Internet
Author: User

namespace to catch the sheep in the hand
{
Class Program
{
public int Jisuan (Int. day)//Create a function, enter day to calculate the total number of sheep
{
int sum=0;
if (day==7)
{
sum = 2;
return sum;//Be sure to add a return deadline
}
sum = (Jisuan (day + 1) + 1) * 2;//To count the day's sheep, you need to count the day's sheep. Sheep sell half a day and add one extra .

return sum; //returns sum of type int

}
static void Main (string[] args)
{
while (true)
{
There are some other functions in the #region//that are not used in this function
//int sum=2;
//for (int i = 0; I <7; i++)
                //{
//sum = (sum + 1) * 2;
                //}
//console.writeline (sum);
#endregion
Console.WriteLine ("Please enter the day");
int m = Convert.ToInt32 (Console.ReadLine ());
int sum = new program (). Jisuan (m);//define a sum of type int to receive the function result of Jisuan function input M-day

Console.WriteLine ("s" + M + "days for" + Sum + "only.) ");
Console.ReadLine ();
}
}
}
}

Recursive function--catching sheep

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.