Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. #!/bin/sh
  2. read x
  3. minus=0
  4. first=1
  5. if [[ $x == -* ]]; then minus=1; fi
  6. sum=0
  7. #if [[ $minus == 1 && $first == 1 ]]; then sum=$((sum-x%10));else sum=$((sum+x%10)) ; fi
  8. for((;x!=0;)); do echo $((x%10)); if [[ $minus == 1 && $first == 1 ]]; then sum=$((sum-x%10)); first=0; minus=0; x=$((x*-1));else sum=$((sum+x%10)) ; fi;x=$((x/10)); done
  9. echo $sum
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement