77问答网
所有问题
linux 设计一个shell程序计算n的阶乘
如题所述
举报该问题
推荐答案 推荐于2016-01-10
#!/bin/sh
if [ -z $1 ];then
echo Please Usage:$0 num
exit 1
fi
counter=$1
factorial=1
while [ $counter -gt 0 ]
do
((factorial=factorial * counter ))
((counter--))
done
echo $factorial
温馨提示:答案为网友推荐,仅供参考
当前网址:
http://77.wendadaohang.com/zd/GqWNpYN33NqGpWGv8pp.html
相似回答
2、
设计一个shell程序计算n的阶乘
。要求:(15分) (1) 从命令行接收参数n...
答:
sum2=
1
until [ $# -eq 0 ];do sum1=$(echo "$sum1+$1" | bc)sum2=$(echo "$sum2*$1" | bc)shift done echo "和 is: $sum1"echo "乘积 is: $sum2"
linux
设计一个shell程序计算n的阶乘
答:
if [ -z $
1
];then echo Please Usage:$0 num exit 1 fi counter=$1 factorial=1 while [ $counter -gt 0 ]do ((factorial=factorial * counter ))((counter--))done echo $factorial
在
Linux
中
shell
编程
求
M-
N的阶乘
,M、N用户输入
答:
exit
1
fi echo "N:"read N 判断N是否非空且小于
N的
整数 if [ -z $N ]then echo "N 必须非空"exit 1 elif ! [[ $N =~ ^-?[0-9]*$ ]]then echo "N 必须为整数"exit 1 elif [ $M -le $N ]then echo "N必须小于M"exit 1 fi let "base = M-N"result=1
阶乘
函数...
linux
shell
关于循环语句的问题
答:
bash 是命令式的语言,第
一个
单词会被当作命令去查询。所以你执行num--,系统会试图搜索名为“num--” 的命令。所以下不能直接执行 num--。应该写成这样:num=$(( num -1 ))或者 let "num--"
编写
Shell程序
,实现功能:
计算N
!,使用函数的方法实现.
答:
2009-12-24 在
linux
里编写一个shell程序,在目录/userdata下创建50个... 7 2012-07-01 编写shell程序创建100个用户名为student00到student99,每个... 2 2012-06-08 2、
设计一个shell程序计算n的阶乘
。要求:(15分) (1) 从命令... 9 2013-07-13 1. 设计一个Shell程序,在/userdata目录下建立50个目...
编写
一个shell
脚本文件,实现以下功能:
答:
0 ];do
n
=$m sum=
1
while [ n -gt 0 ];do sum=$((sum*n))echo "sum="$sum echo "n="$n n=$((n-1))done total=$((total+sum))m=$((m-1))echo "total=$total"done 我的电脑不知道为什么 写不了for循环 ,所以就用while 代替了 你也可以写for 循环 ,比较直观点 ...
linux
shell
编程wenti
答:
手头刚好
一个
判定整数的脚本,发一下:!/bin/bashecho $(( $1%1 )) > nulif [ $? -eq 0 ];thenecho it is integerelseecho it is not integerfi
大家正在搜
linux怎么编写shell程序
linux编写shell程序
linux编写shell程序步骤
linux简单的shell编程
linux的shell编程与调试
linux编写shell脚本程序
linux怎么进入shell编程
linuxshell编程案例
linux怎么打开shell
相关问题
2. 编写一个shell程序,用递归法计算整数n的阶乘。要在...
2、设计一个shell程序计算n的阶乘。要求:(15分) (...
Linux操作,8、设计一个shell程序计算n的阶乘。要求...
编写一个shell脚本程序,实现100的阶乘并输出
编写一个shell脚本程序,实现100的阶乘并输出
shell脚本实现n的阶乘
1:编辑shell脚本factorial.sh,计算1到10...
在Linux中shell编程求M-N的阶乘,M、N用户输入