Linux下用shell编写斐波那契数列前十项之和
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
写出斐波那契的前十项和,代码如下:
#!/bin/bash
a=1
b=1
echo -n -e "$a\t$b"
let "n=a+b"
count=4
while [ $count -gt 0 ]
do
let "a=a+b"
let "b=b+a"
echo -n -e "\t$a\t$b"
let "n+=a+b"
let "count=count-1"
done
echo
echo "The sum is $n"
#end
运行结果:
[root@localhost dajun]# bash c
1 1 2 3 5 8 13 21 34 55
The sum is 143
然后又发现了一种简单的(主要是方便记忆)
#!/bin/bash
a=1
b=1
c=0
s=0
for((i=0; i<10; ++i));do
echo "$a"
let s+=a
let c=a+b
let a=b
let b=c
done
echo "sum=$s"
运行结果同上;
GitHub 加速计划 / li / linux-dash
6
1
下载
A beautiful web dashboard for Linux
最近提交(Master分支:4 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
已为社区贡献3条内容
所有评论(0)