tampurus

2.1 greater among three or two numbers

Dec 17th, 2021 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.52 KB | None | 0 0
  1. # Maximum of two numbers
  2. echo enter two numbers with spaces
  3. read a b
  4. if [ $a -eq $b ]
  5.     then
  6.     echo both are equal
  7. elif [ $a -gt $b ]
  8.     then
  9.     echo $a is greater
  10. else
  11.     echo $b is greater
  12. fi
  13.  
  14. # Maximum of three numbers
  15. echo enter three numbers with spaces
  16. read a b c
  17. if [ $a -eq $b -a $b -eq $c ]
  18.     then
  19.     echo all three are equal
  20. elif [ $a -gt $b -a $a -gt $c ]
  21.     then
  22.     echo $a is greater
  23. elif [ $b -gt $a -a $b -gt $c ]
  24.     then
  25.     echo $b is greater
  26. else
  27.     echo $c is greater
  28. fi
Add Comment
Please, Sign In to add comment