<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> </body> </html> <script> var a=prompt("请输入一个整数"); if(a!=null) { var b=isNaN(a); if(b==false) { var sum=0; var c=parseInt(a); var jiecheng=1; for(var i=1;i<=c;i++) { jiecheng=jiecheng*i; sum=sum+jiecheng; } alert("1-"+a+"阶乘和"+sum); } else{alert("你输入的不是整数");} } else{} </script>
运行
时间: 2024-12-16 04:48:54