39 lines
939 B
HTML
39 lines
939 B
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Document</title>
|
||
<script>
|
||
// 递归 就是在函数内 调用自身
|
||
// 阶乘的函数
|
||
// 5的阶乘 = 5*4*3*2*1
|
||
// n的阶乘 = n*(n-1)*(n-2)*(n-3)...*1
|
||
// n*(n-1)*(n-1-1)*(n-1-1-1)*(n-1-1-1-1)....*1
|
||
function jc(n){
|
||
if(n==1){
|
||
return 1;
|
||
}else{
|
||
return n*jc(n-1)
|
||
}
|
||
}
|
||
|
||
// 4
|
||
// 4*jc(4-1) 4*jc(3)
|
||
// 4*jc(3) 4*3*jc(3-1)
|
||
// 4*3*jc(2)
|
||
// 4*3*2*jc(2-1)
|
||
// 4*3*2*jc(1)
|
||
// 4*3*2*1
|
||
|
||
var jiecheng=jc
|
||
jc=null
|
||
var res=jiecheng(5)
|
||
console.log(res)
|
||
</script>
|
||
</head>
|
||
<body>
|
||
|
||
</body>
|
||
</html> |