In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to achieve n-factorial in php". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to achieve n-factorial in php".
1. General recursive implementation, it is easy to write the factorial calculation code according to the recursive general formula fact (n) = n * fact (nMel 1).
The advantage of ordinary recursive implementation is that the code is relatively simple, and the same process as the general formula makes the code easy to understand. The disadvantage is that due to the need to call themselves frequently, need a large number of stack operations, the overall computational efficiency is not high.
Function fact (int $n): int {if ($n = = 0) {return 1;} return $n * fact ($n-1);}
2. The ordinary loop implementation has the flavor of dynamic programming, but due to the low frequency of intermediate state variables, no additional storage space is needed.
Therefore, it is simpler than the general dynamic programming algorithm. The ordinary recursive method is calculated from the top down (from n to 1), while the ordinary loop is calculated from the bottom up.
Function fact (int $n): int {$result = 1; $num = 1; while ($num
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.