linux中shell编程A1到An的和,An=A1+A2+......+A(n-1)
linux中shell编程题:n不超过50A1到An的和,An=A1+A2+......+A(n-1)求完整的程序急!!...
linux中shell编程题:
n不超过50
A1到An的和
,An=A1+A2+......+A(n-1)
求完整的程序
急!! 展开
n不超过50
A1到An的和
,An=A1+A2+......+A(n-1)
求完整的程序
急!! 展开
展开全部
#!/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=2;i<=n;i++){for(j=1;j<i;j++){A[i]+=A[j]}}}
END{for(k=1;k<=n;k++){sum+=A[k]};print "The value of A1 + ... + A"n" is "sum}'
=>A1 + ... + An = A1 * 2^(n-1)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询