JS Statement Example

Source: Internet
Author: User

Example one: List all the odd numbers within 100

This problem is used in the way of exhaustive, that is, all the data are listed to check again, from which to find the eligible.

If the question asks for a list of all even numbers, simply change the IF (i%2==1) 1 to 0.

Example two: Summing up and summing: asking for the sum of 0-99

This problem applies to the iterative approach, that is, the results of the last calculation to the current cycle to use, until the results are obtained.

Example three: Making multiplication tables

The subject applies a nested method of loops that nest a for loop into another for loop to achieve a common result of two variables.

Example four: Basketball from the height of 5 meters, the height of each bounce is the last 30%. Q. How many times has the basketball height been less than 0.1 meters after bouncing?

This problem is used in the while loop because its number of cycles cannot be determined.

Example five:

A chessboard has 64 squares, the first one to put 1 sesame seeds, the second to put 2, the third Geffon 4 tablets, and so on, ask how many kilograms of sesame seeds to fill the board?
(Each sesame weight 0.000001kg)

This problem is also used in iterative methods, because the final request for the total number of sesame, so just the weight of the sesame can be.

Example six: There are 1 yuan, 2 yuan, 5 yuan of money, now together into 20 yuan, how many kinds of possibilities?

This problem applies to the loop nesting, exhaustive, screening results.

Job Title:

1. The thickness of a piece of paper is 0.0001 meters, fold the paper, fold how many times the thickness exceeds the height of Everest 8848 meters

This problem is used while loop because it is not possible to determine the number of folds in the fold.

2. There are a pair of young rabbits, 1 months after the young rabbit into a small rabbit, the rabbit 1 months later into a rabbit and gave birth to a pair of young rabbits, asked 7 months after how many pairs of rabbits, rabbits, rabbits, Cheng logarithm of how much respectively.

Know:

Current month young rabbit = last month's Rabbit + last month rabbit;

Current month Bunny = Last month's young rabbits;

Current month into rabbit = last month into rabbit + last month bunny;

In this topic, because "the current month into a rabbit = last month into a rabbit + last month Bunny", and "the current month of the rabbit = last month of the Hare + last month Rabbit" This two is known as the "month before the rabbit = the current month into a rabbit"

Because of the first pair of young rabbits, so because the current month into a rabbit list, and then let the "Current month Bunny = last month", "the former month of the young rabbit = The current month into a rabbit" list can be obtained results.

3. Badminton racket 15 yuan, ball 3 yuan, water 2 yuan. 200 USD At least one per species, how much is it possible?

Conditions: Badminton racket up to buy 13 ball up to buy 66 water up to buy 100

This problem is similar to example six, which is applied to the loop nesting, exhaustive, and filtering results.

4. Rooster 2, hen 1, chicken half, each of at least one, 100 buy 100 chickens how many possibilities

Condition: Rooster Max 50, hen max 100, chick up to 200

This problem is similar to the previous question, but there is a requirement, that is, use and "&&", will be two of the requirements and use together.

JS Statement Example

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.