# "11" to find the maximum and maximum values of a set of arrays, the minimum value, the minimum value of the angle index and the average

Source: Internet
Author: User

Requirement: A set of data that is graded by a group of judges.

1. Find their maximum and minimum values.
2. The corner label of the maximum minimum value
3. To remove the average after the maximum and minimum values

Code:

`1<?PHP2     \$arr=Array(1,2,3,4);3     //Minimum Value4 //idea: 44,5,3,333,445,99,54,332,-65 //1. Define variables, one record subscript \$index, one record minimum value \$minvalue6 //2. If the minimum value is a number with a subscript of 07 //3. Compare the value that is considered to be the minimum to the number in the array8 //4. If \$minvalue is larger than a certain number in the array, the number is not the minimum value. Exchange subscript and minimum values9     functionMinfunction (\$arr){Ten         \$index=0; One         \$minvalue=\$arr[0]; A          for(\$i= 1;\$i<Count(\$arr) ;\$i++) {  -             if(\$minvalue>\$arr[\$i]) { -                 \$index=\$i; the                 \$minvalue=\$arr[\$i]; -             } -         } -         return \$index; +     } -     \$a=minfunction (\$arr); +     //echo \$a; A     EchoThe minimum value is\$a, his score was\$arr[\$a]"; at     Echo"<br/>"; -     //Maximum Value - //idea: Same as the minimum idea -     functionMaxfunction (\$arr){ -     \$index=0; -     \$minvalue=\$arr[0]; in      for(\$i= 1;\$i<Count(\$arr) ;\$i++) {  -         if(\$minvalue<\$arr[\$i]) { to             \$index=\$i; +             \$minvalue=\$arr[\$i]; -         } the     } *     return \$index; \$ }Panax Notoginseng     \$b=maxfunction (\$arr); -     //echo \$a; the     EchoThe maximum value is\$b, his score was\$arr[\$b]"; +     Echo"<br/>"; A     //Average the //ideas: + //Define a variable record total score number - //2. Add a value other than the maximum value to the minimum value \$ //3. Divide by Count (\$arr)-2 to get the average. \$     \$sum=0; -      for(\$i= 0;\$i<Count(\$arr) ;\$i++) {  -         //echo \$a. " = = = ". \$b." ---". \$i." <br/> "; the //\$c = (\$i! = \$a) && (\$i! = \$b); - //Var_dump (\$c);Wuyi //NOTE: The following conditions && the meaning of both are true before executing the following statement the         if((\$i!=\$a) && (\$i!=\$b)) {             -             \$sum+=\$arr[\$i]; Wu             //echo \$sum. " <br/> "; -         } About     } \$     Echo"Remove the total of the maximum and minimum values into\$sum"." <br/> "; -     Echo"Average is".\$sum/(Count(\$arr)-2); -     Echo"<br/>"; -?>`

Results:

The wrong points encountered in the course of doing a problem:

• A comparison of the 52nd row of values is written (\$arr [\$i]!= \$arr [\$a] && (\$arr [\$i]!= \$arr [\$b]), and of course the result is true. Easier and quicker to compare subscripts
• The 52nd line operator, written as | |. After a long struggle how to 4 count he counted in. = = (silent for a burst). The original operator was wrong. Must be two to be true to overlay the value of sum

Summarize:

1. Find maximum and minimum values, use circular traversal sorting (sort by: bubble sort, select sort, courier Sort)
2. Operator:&&, and (all true), or | | (any one is true). For details, refer to http://www.cnblogs.com/8013-cmf/p/7722966.html

"11" to find the maximum and maximum values of a set of arrays, the minimum value, the minimum value of the angle index and the average

Related Keywords:

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.