Learning programming is important to mastering programming ideas

Source: Internet
Author: User

To find the maximum, sum, and return of variables these three types of programming topics that are very important for mastering core ideas are the three kinds of topics that represent three kinds of ideas, all of which are very important ideas, It is important to master the core of these three types of programming questions rather than just remembering the three types of programming topics.

Maximum value: If the maximum value is three digits, we can also use the if else this function, if there are a lot of numbers, we need to set a new variable for the maximum value is out, set the sum out, the idea of the maximum value becomes our sum is equivalent to a basket, And then a row of numbers in front of us, we brought in a number of baskets, and then brought in a number of baskets, if the number of later than the basket in the number of large we will leave behind the number, the basket in the number of lost, if the number of baskets than the later number of large, leaving the basket in the number. So it's a circular action to keep a number from a row of numbers and put it in the basket. Take out this number is a, and set for the loop, the maximum set for Max,max<a is Max=a, that is, as long as the number of the basket in the big left, not to move, how many times the number of cycles, Finally, no matter how many numbers can find the maximum value.

Summation: It is also a typical application of a new idea. and set to sum, then sum is also a basket, put the number of the added to a basket, and finally you can get these numbers and values. To set the number to add to the a,a and then set to the loop (that is, the action to put into the basket again and again), Sum=sum+a,sum constantly as a new value to continue to receive a, and finally no matter how many numbers we can get their final and value. Summation is also the idea of using numbers to load baskets.

Exchange variable: The Exchange variable in the maximum value can be used, such as the comparison of three numbers to find the maximum value, first compare the first two number who big, big put the front, small put behind, and then compare the two size, big put in front, small put behind, so, three number is according to the order from big to small in the arrangement. The idea of exchanging variables is to put the idea of an empty bottle, you must first int temp, that is, first in the number to exchange into an empty bottle, and then Exchange. Swap a pair of numbers with an empty bottle, then swap a pair of numbers again with an empty bottle, exchange several times to use a few empty bottles.

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.