您的位置:首页 > 其它

使用awk求一个数字的阶乘

2013-03-26 15:09 246 查看
BEGIN{print( "enter number:")
}
#check if is a number
$1 ~/^[0-9]+$/
{
num=$1
if(num == 0)
fact=1
else
fact=num
for(x=num-1;x>=1;x--){
fact*=x
}
print fact
exit
}
#not a valid number
{printf( "not a number.")}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐