JS实现求5的阶乘示例
作者:黎成诃月 时间:2024-04-30 10:09:43
本文实例讲述了JS实现求5的阶乘运算操作。分享给大家供大家参考,具体如下:
方案一:利用while循环
function factorial(num){
var result = 1;
while(num){
result *= num;
num--;
}
return result;
}
console.log(factorial(5))//120
运行结果:
方案二:利用函数递归
function factorial(num){
if(num <= 0){
return 1;
}else{
return num*arguments.callee(num-1);
}
}
console.log(factorial(5))//120
运行结果:
希望本文所述对大家JavaScript程序设计有所帮助。
来源:https://blog.csdn.net/weixin_40292626/article/details/80542450
标签:JS,阶乘
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
update.where无索引导致MySQL死锁问题解决
2024-01-28 01:21:25
![](https://img.aspxhome.com/file/2023/4/112894_0s.png)
TensorFlow实现Batch Normalization
2023-02-03 05:20:15
![](https://img.aspxhome.com/file/2023/8/79718_0s.png)
Tensorflow 2.1完成对MPG回归预测详解
2023-06-30 07:31:36
![](https://img.aspxhome.com/file/2023/9/115819_0s.png)
SUSE Linux下源码编译方式安装MySQL 5.6过程分享
2024-01-14 21:55:50
oracle 性能优化建议小结
2010-04-22 16:32:00
python机器学习之随机森林(七)
2023-10-20 00:25:13
Pytorch训练过程出现nan的解决方式
2021-04-21 08:12:08
![](https://img.aspxhome.com/file/2023/4/76824_0s.jpg)
SQL点滴24 监测表的变化
2011-09-30 11:38:41
嵌入式Web视频点播系统实现方法
2007-10-10 21:17:00
PHP实现加减乘除最简单的实例分享
2023-06-14 16:17:41
超详细注释之OpenCV旋转图像任意角度
2021-04-20 23:47:29
![](https://img.aspxhome.com/file/2023/9/93819_0s.jpg)
一文搞懂Vue3中的异步组件defineAsyncComponentAPI的用法
2024-04-29 13:09:08
FrontPage 2002应用技巧四则
2008-08-17 10:57:00
用pip给python安装matplotlib库的详细教程
2021-02-02 00:02:45
![](https://img.aspxhome.com/file/2023/4/97254_0s.jpg)
python中open函数的基本用法示例
2021-08-03 20:42:31
SQL Server子查询的深入理解
2024-01-15 14:09:46
![](https://img.aspxhome.com/file/2023/9/89649_0s.png)
python实现k-means聚类算法
2022-03-16 22:06:07
![](https://img.aspxhome.com/file/2023/4/120604_0s.jpg)
python3 写一个WAV音频文件播放器的代码
2023-04-09 05:06:36
python中类和实例如何绑定属性与方法示例详解
2022-01-02 07:22:12
自定义Django_rest_framework_jwt登陆错误返回的解决
2021-02-27 22:07:32
![](https://img.aspxhome.com/file/2023/6/76006_0s.jpg)