Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ans=0
- echo -n "f->Factorial F->Fibonacci S->Sum of Series D->Sum of Digits: "
- read n
- case $n in
- f):
- ans=1
- echo -n "Enter a number: "
- read ip
- while [ $ip -ne 1 ]
- do
- let ans*=ip
- let ip=ip-1
- done;;
- F):
- a=0
- b=1
- echo -n "Enter the number of terms: "
- read ip
- if [ $ip -lt 1 ]
- then echo "invalid input"
- exit 1
- fi
- if [ $ip -ge 1 ]
- then echo -n "$a "
- let ans=a
- fi
- if [ $ip -ge 2 ]
- then echo -n " $b "
- let ans=b
- fi
- let ip=ip-2
- while [ $ip -gt 0 ]
- do
- let c=a+b
- echo -n " $c "
- a=b
- b=c
- let ans=c
- let ip=ip-1
- done
- ;;
- S):
- ip=1
- echo "Enter numbers to add. Press 0 to end."
- while [ $ip -ne 0 ]
- do
- read ip
- let ans+=ip
- done;;
- D):
- echo -n "Enter a number: "
- read ip
- if [ $ip -lt 0 ]
- then let ip=-ip
- fi
- while [ $ip -ne 0 ]
- do
- let r=ip%10
- let ans+=r
- let ip=ip/10
- done;;
- *):
- echo "Invalid choice"
- exit 1;;
- esac
- echo "The answer is $ans."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement