The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Sort
By Guest on 26th March 2024 04:03:19 AM | Syntax: PYTHON | Views: 82



New Paste New paste | Download Paste Download | Toggle Line Numbers Show/Hide line no. | Copy Paste Copy text to clipboard
  1. #!bin/bash
  2. echo "Enter limit:"
  3. read n
  4. echo "Enter the numbers"
  5. for((i=0;i<n;i++))
  6. do
  7.         read a[i]
  8. done
  9. echo "Numbers before sorting"
  10. echo ${a[@]}
  11. for((i=0;i<n;i++))
  12. do
  13. for((j=i+1;j<n;j++))
  14. do
  15.         if [ ${a[i]} -gt ${a[j]} ]
  16.         then
  17.                 t=${a[i]}
  18.                 a[i]=${a[j]}
  19.                 a[j]=$t
  20.          fi
  21.     done
  22. done
  23.  
  24. echo "Numbers after sorting"
  25. echo "${a[@]}"





sort