Application of C # for loop iteration method to exhaustive method

Source: Internet
Author: User

Iteration

Rabbit with Rabbit

Class CLASS5

{

static void Main (string[] args)

{

int TU1 = 1, tu2 = 1; TU1 is the number of rabbits in the penultimate month, TU2 is the number of rabbits in the second month.

int tu=0;//The number of rabbits required for this month.

for (int i = 3; I <=; i++)

{tu = tu1 + tu2;

TU2 = TU1;

TU1 = Tu;

}

Console.WriteLine (TU);

}

}

Age: 6 children lined up, asked how old he was, said he was 2 years younger than the second, asked how old he was, he said he was 2 years younger than the third, and so on, and asked how old he was at 6th, saying he was 16. Q How old is the first child?
Class Class2
{
static void Main (string[] args)
{
int age = 16; Initially, the 6th child age is saved, each cycle will be reduced by 2, representing the age of the 5,4,3,2,1 child respectively.
for (int i = 5; I >= 1; i--)
{
age = age-2;
}
Console.WriteLine (age);
}
}
}

Monkeys eat peaches.
There is a monkey and a bunch of peaches in the park. The monkey eats half of the peaches a day and throws away a bad half of the remaining number. On the 7th day the monkey opened his eyes and found only one peach left, and asked how much it had.
190
Class Class4
{
static void Main (string[] args)
{
int count = 1;
for (int i=6;i>=1;i--)
{
Count = (count + 1) * 2;
}
Console.WriteLine (count);
}
}
}

Poor lift

2. There are three kinds of coins: 1 points, 2 points, 5 points. To combine 1 hairs 5, what are the combinations?

static void Main (string[] args)
{
for (int a=0;a<=15;a++)//a The number of coins representing 1 cents
{
for (int b=0;b<=7;b++)//b The number of coins representing 2 cents
{
for (int c=0;c<=3;c++)//c represents the number of 5 cent coins
{
if (a*1+b*2+c*5 = = 15)
{
Console.WriteLine ("1 cent coins need to" +a+ ", 2 cent of the coins need" +b+ ", 5 cent of the coins need to" +c+ ");
}
}
}
}
}
}
}

Application of C # for loop iteration method to exhaustive method

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.