linux shell编程题

linux shell编程题,第1张

===========================================================================

#!/bin/bash

read -p "Please input flag:" flag

sum=`seq -s $flag $1 $2 | bc 2>/dev/null`

if [[ $flag == "+" || $flag == "-" ]]

then

echo The $1$flag$2 is $sum

echo The $1$flag$2 is $sum >>file

else

echo error

echo error >>file

fi

运行:

[root@localhost shell]# bash test3.sh 1 10

Please input flag:+

The 1+10 is 55

=====================================================================

第二题,说实话,没看懂要求~~~所以没法写,

交互式输入四个参数前缀 位数 开始序号 终止序号 ,这四个参数是用来干什么的???

你把要求写明白了,我再作答

#!/bin/sh

echo "Please input the value of A1:"

read A1

echo "Please input the value of n(no larger than 50):"

read n

echo | awk -v A1=${A1} -v n=$n 'BEGIN{A[1]=A1}

      {for(i=2i<=ni++){for(j=1j<ij++){A[i]+=A[j]}}}

      END{for(k=1k<=nk++){sum+=A[k]}print "The value of A1 + ... + A"n" is "sum}'

=>A1 + ... + An = A1 * 2^(n-1)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8444677.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-16
下一篇 2023-04-16

发表评论

登录后才能评论

评论列表(0条)

保存