Advertisement
Shailrshah

Sum of Series and Digits

Aug 11th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.39 KB | None | 0 0
  1. #!/bin/bash
  2. sum=0
  3. echo -n "Sum of 1.Series 2.Digits: "
  4. read n
  5. case $n in
  6. 1):
  7.     ip=1
  8.     echo "Enter numbers to add. Press 0 to end."
  9.     while [ $ip -ne 0 ]
  10.     do
  11.         read ip
  12.         let sum+=ip
  13.     done
  14.     ;;
  15. 2):
  16.     echo -n "Enter a number: "
  17.     read ip
  18.     while [ $ip -ne 0 ]
  19.     do
  20.         let r=ip%10
  21.         let sum+=r
  22.         let ip=ip/10
  23.     done
  24.     ;;
  25. *):
  26.     echo "Invalid choice"
  27.     exit 1
  28.     ;;
  29. esac
  30. echo "The sum is $sum"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement