PHP to find the sum of all even numbers between two

Source: Internet
Author: User
Define Show Class
class defines the method sum
Two numbers passed in the method
Within the method body, all even-numbered and two numbers are calculated
The results will be calculated to return
Results after output return
The output form is as follows
Two numbers between all even-numbered and: 30

Note: The incoming two number is smaller than the first incoming large number of the second incoming two numbers cannot be equal.

The code is as follows:

 
 $two) {for ($i = $two; $i <= $one; $i + +) {if ($i%2==0) {$num + = $i;}} else if ($two > $one) {for ($i = $one; $i <= $two; $i + +) {if ($i%2==0) {$num + = $i;}} Else{return "error, two numbers cannot be equal";//If two numbers equal}return "two number of all even numbers and for". $num;}} Instantiate class $show=new Show ();//Call echo $show->sum (20,30);//Enter two values

The above introduces PHP to find out two of the sum of all the even, including PHP, between the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.