PHP array exercises (2)

Source: Internet
Author: User

Question: enter five numbers in the input box (the five numbers are separated by spaces). Use a one-dimensional array to compileProgramCalculate their average value (retain 2 decimal places ). You can think about how to do this on your own.

ReferenceCode:

<HTML>  PHP  //  Receive and submit (input value) Request      $ Grade = @ $ _ Request ['Grade' ];  //  Echo $ grades; // split it into an array      $ Grades =Explode ("", $ Grade  );  //  Print_r ($ grades); // defines the total number of variables      $ Total = 0 ;  //  Calculate the total score      For ( $ I = 0; $ I < Count ( $ Grades ); $ I ++){  $ Total + = $ Grades [ $ I  ];}  //  The round function retains decimal places | this is a rounding method that retains 2 decimal places // The echo 'average is: '. Round ($ total/count ($ grades), 2 ); ?> <Form action = "array01.php" method = "Post"> Enter : <Input type = "text" name = "Grade" value = "<? PHP echo $ Grade ;?> "> <Input type =" Submit "value =" Submit "> </form> <? PHP  // The number_format () function is a reserved number of digits, While formatting the number with a thousand characters      Echo 'Mean :'. Number_format ( $ Total / Count ( $ Grades ), 2 );  //  Echo 'average: '. Round ($ total/count ($ grades), 2 ); ?> </Body> 

 

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.