シェル Fibonacciの数列
ファイル名:Fibonacci.sh
ソース:
#!/bin/bash
echo “いくつのFibonacciの数列が必要 ?"
read total
x=0
y=1
i=2
echo “Fibonacci Series up to $total terms :: "
echo “$x"
echo “$y"
while [ $i -lt $total ]
do
i=`expr $i + 1 `
z=`expr $x + $y `
echo “$z"
x=$y
y=$z
輸出結果:
[root@tecmint ~]# chmod 755 Fibonacci.sh
[root@tecmint ~]# ./Fibonacci.sh
How many numbers do you want of Fibonacci series ?
10
Fibonacci Series up to 10 terms ::
0
1
1
2
3
5
8
13
21
34