Advertisement
Shailrshah

Display Smallest and Largest Number

Aug 11th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.27 KB | None | 0 0
  1. #!/bin/bash
  2. echo -n "Enter a number: "
  3. read n
  4. small=$n
  5. large=$n
  6. for ((i=1; i<5; i++)){
  7.     echo -n "Enter a number: "
  8.     read n
  9.     if [ $large -lt $n ]
  10.     then
  11.         large=$n
  12.     fi
  13.     if [ $small -gt $n ]
  14.     then
  15.         small=$n
  16.     fi
  17. }
  18. echo "Smallest: $small"
  19. echo "Largest: $large"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement