Poor lifting Iteration 03/10

Source: Internet
Author: User

Poor lifting Iteration 03/10

The For loop has two classes:

1. Poor lifting:

Go through all the possible situations and use the IF condition to filter out the conditions that satisfy the condition.

The For loop has two classes:

2. Poor lifting:

Go through all the possible situations and use the IF condition to filter out the conditions that satisfy the condition.

For loop for (int i = 1; i<=5;i++)

{

Circulation body;

}

While style int i= 1;

while (expression (i<=5))

{

Circulation body;

State change (i++);

}

Do While style do

{

Circulation body;

State change (i++);

}while (expression (i<=5))

Practice:

    1. Unit to send a 150 yuan shopping card, take to the supermarket to buy three kinds of washing supplies. Shampoo 15 yuan, soap 2 yuan, toothbrush 5 yuan. Please just spend 150 yuan, how many kinds of buy law, no kind of buying method are all buy a few samples?

Set Shampoo x 150/15==10

Toothbrush y 150/5==30

Soap Z 150/2==75

int a = 0;

int sum = 0;

for (int x = 0; x <= × x + +)

{

for (int y = 0; y <=; y++)

{

for (int z = 0; z <=; z++)

{

sum++;

if (x + 5 * y + 2 * z = = 150)

{

a++;

Console.WriteLine ("First" + A + "seed buy method, shampoo" + x + "bottle, toothbrush" + y + "put, soap" + z + "block.) ");

}

}

}

}

Console.WriteLine ("A total of" + A + "buy method. ");

Console.WriteLine ("Total calculation" + Sum + "times.") ");

2, Hundred chicken Hundred Money: Rooster 2 text Money A, hen 1 text money One, chicken half text money A, total only 100 text money, how to gather enough 100 chickens in the case just spend 100 money?

Rooster x,50

Hen y,100

Chick z,200

int sum = 0;

int sum1 = 0;

for (int x = 0; x <= 50;x++)

{

for (int y = 0; y <= 100;y++)

{

for (int z = 0; z <= 200;z++)

{

sum1++;

if ((x+y+z==100) && (2*x+1*y+0.5*z==100))

{

sum++;

Console.WriteLine ("+sum+" Method: Rooster "+x+" only, hen "+y+" only, Chick "+z+" only. ");

}

}

}

}

Console.WriteLine ("+sum1+" is calculated in total.) ");

3, the paper can be folded in infinite times, the paper thickness of 0.07 mm. How many times do I have to fold at least 8848?

int a = 7;

int b = 884800000;

for (int i = 1;; i++)

{

A *= 2;

if (a >= b)

{

Console.WriteLine ("This is the first" + i + "fold.) ");

Console.WriteLine ("Height is" + a);

Break

}

}

Poor lifting Iteration 03/10

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.