88问答网
所有问题
当前搜索:
shell编程求n的阶乘
2、设计一个
shell
程序
计算n的阶乘
。要求:(15分) (1) 从命令行接收参数n...
答:
echo "$*" | sed 's/ //g' | egrep "^[0-9]+$" >/dev/null 2>&1 if [[ $# -eq 0 || $? -gt 0 ]];then echo "Usage:./test.sh 参数(只允许是整数)"exit 1 fi sum1=0 sum2=1 until [ $# -eq 0 ];do sum1=$(echo "$sum1+$1" | bc)sum2=$(echo "$su...
Linux操作,8、设计一个
shell
程序
计算n的阶乘
。要求: (1)从命令行接收...
答:
0-9]*) echo 你输入的不是合法数字 exit 1;;*)
n
=$1;;esacif [ $n -le 0 ];then echo 你输入的不是正整数exit 1 fifrac=1while [ $n -gt 0 ]do frac=$((frac * n))n=$((n - 1))doneecho
阶乘
为:$fracecho 学号 ...
shell
程序,根据输入的参数
n
,
计算
得
阶乘
答:
用函数递归。!/bin/bash multiply(){ if [ $1 -gt 1 ]; then result=`expr $result \* $1`next=`expr $1 - 1`multiply $next fi } if [ $# -ne 1 ]; then echo -e "Please input a parameter!\
n
Usage: $0 [n]"exit 1 fi result=1 if [ $1 -eq 1 ]; then :elif ...
linux 设计一个
shell
程序
计算n的阶乘
答:
echo Please Usage:$0 num exit 1 fi counter=$1 factorial=1 while [ $counter -gt 0 ]do ((factorial=factorial * counter ))((counter--))done echo $factorial
...
计算
1到10
的阶乘
。2:
编写shell
脚本max.sh,求所有命令行参数中的最...
答:
(i=0;i<$num;i++))doi=`expr $i + 1`sum=`expr $sum \* $i`doneecho "$num
的阶乘
是 $sum"}for i in {1..10}dofactorial_1 $idone#!/bin/bash#max.shmp=$*echo $mp|sed 's/ /\
n
/g'|sort -n >uuu.$$tail -1 uuu.$$rm -f *.$$#完全手打,忘采纳 ...
shell编程
递归
求阶乘
答:
fn_calc() { if [ $number -le 0 ];then return 0 else fn_calc `expr $number - 1`fn_result=`expr $fn_result \* $number`fi return 0 } 这里的$number 都应当改成$1 输出也应当在函数内完成
5、
shell编程
综合设计 编写一个显示菜单的shell程序,利用函数实现简单...
答:
while :doecho "===** (1)
计算
1到n的奇数之和; *** (2)计算1到
n的阶乘
; *** (3)计算1到n的所有质数; *** (4)退出程序。 **==="read -p "Please enter function select and number:" m n[ $m -eq 4 ]&&exitif echo $m|grep "^[...
利用所学的
shell
命令,写出
计算
10
的阶乘
的脚本程序,如何编译如何进行...
答:
!/bin/sh factorial=1 for a in `seq 1 10 `do factorial=`expr $factorial\*$a`done echo "10! = $factorial"
linux
shell
关于循环语句的问题
答:
bash 是命令式的语言,第一个单词会被当作命令去查询。所以你执行num--,系统会试图搜索名为“num--” 的命令。所以下不能直接执行 num--。应该写成这样:num=$(( num -1 ))或者 let "num--"
从键盘输入一个正整数
n
,
计算
并显示其
阶乘
值。
答:
long long fact(int n){ unsigned long long ans;for(ans=1;n>1;n--)ans *=n;return ans;} 注意:printf(" 本机: ULLONG_MAX = %llu\n",ULLONG_MAX);是检测本机可以容纳的最大无符号整数,所以
n的阶乘
不能超过此数值。编译器必须满足c99规范。
1
2
3
4
5
6
7
8
9
10
涓嬩竴椤
灏鹃〉
其他人还搜
编程求1到n的阶乘的和
matlab编程求n的阶乘
linux简单的shell编程
shell计算n的阶乘
linux怎么编程10的阶乘
linux求n的阶乘
n的阶乘编程
1到n的阶乘的程序设计
linux shell编程题