js如何实现1到50的阶乘,下面web建站小编给大家详细介绍一下1到50的阶乘的总和!
具体代码如下:
for (var i = 1; i <= 50; i++) { var sum = 1; for (var j = 1; j <= i; j++) { sum *= j; } console.log( i+"的阶乘为: " + sum); } //1的阶乘为: 1 //2的阶乘为: 2 //3的阶乘为: 6 //4的阶乘为: 24 //5的阶乘为: 120 //6的阶乘为: 720 //7的阶乘为: 5040 //8的阶乘为: 40320 //9的阶乘为: 362880 //10的阶乘为: 3628800 //11的阶乘为: 39916800 //12的阶乘为: 479001600 //13的阶乘为: 6227020800 //14的阶乘为: 87178291200 //15的阶乘为: 1307674368000 //16的阶乘为: 20922789888000 //17的阶乘为: 355687428096000 //18的阶乘为: 6402373705728000 //19的阶乘为: 121645100408832000 //20的阶乘为: 2432902008176640000 //21的阶乘为: 51090942171709440000 //22的阶乘为: 1.1240007277776077e+21 //23的阶乘为: 2.585201673888498e+22 //24的阶乘为: 6.204484017332394e+23 //25的阶乘为: 1.5511210043330986e+25 //26的阶乘为: 4.0329146112660565e+26 //27的阶乘为: 1.0888869450418352e+28 //28的阶乘为: 3.0488834461171384e+29 //29的阶乘为: 8.841761993739701e+30 //30的阶乘为: 2.6525285981219103e+32 //31的阶乘为: 8.222838654177922e+33 //32的阶乘为: 2.631308369336935e+35 //33的阶乘为: 8.683317618811886e+36 //34的阶乘为: 2.9523279903960412e+38 //35的阶乘为: 1.0333147966386144e+40 //36的阶乘为: 3.719933267899012e+41 //37的阶乘为: 1.3763753091226343e+43 //38的阶乘为: 5.23022617466601e+44 //39的阶乘为: 2.0397882081197442e+46 //40的阶乘为: 8.159152832478977e+47 //41的阶乘为: 3.3452526613163803e+49 //42的阶乘为: 1.4050061177528798e+51 //43的阶乘为: 6.041526306337383e+52 //44的阶乘为: 2.6582715747884485e+54 //45的阶乘为: 1.1962222086548019e+56 //46的阶乘为: 5.5026221598120885e+57 //47的阶乘为: 2.5862324151116818e+59 //48的阶乘为: 1.2413915592536073e+61 //49的阶乘为: 6.082818640342675e+62 //50的阶乘为: 3.0414093201713376e+64
只显示50的阶乘
var sum = 1; for (var i = 1; i <= 50; i++) { sum *= i; } console.log( "50的阶乘为: " + sum); //50的阶乘为: 3.0414093201713376e+64
标签: 阶乘算法
上面是“js如何实现阶乘(求1到50的阶乘)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_3151.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!