Php method for solving a number factorial based on recursive function

Source: Internet
Author: User
This article mainly introduces PHP based on simple recursive function to find a number of factorial method, combined with the example of the PHP recursive function definition and mathematical operation of simple operation skills, the need for friends can refer to the next

In this paper, we describe a method for calculating the factorial of a number based on simple recursive function of PHP. Share to everyone for your reference, as follows:

First, the question:

To find the factorial of a number A, then a!=a* (A-1) * (a-2) * (a-3) *......*2*1. For example, 6 factorial 6! =6*5*4*3*2*1=720. So, how do you get the factorial of any number by using PHP code?

Second, the implementation of code:

<?phpfunction Demo ($a) {  if ($a > 1) {    $r = $a * Demo ($a-1);  } else {    $r = $a;  }  return $r;} $a = 6;echo $a. "The value of the factorial." Demo ($a);? >

Third, show the result:

The above is the whole content of this article, I hope that everyone's study has helped.


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.