Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #!/bin/sh
  2. i=0
  3. psps=0
  4. pspl=0
  5. plpl=0
  6. plps=0
  7. j=1
  8. jmax=`cat $1 | tr -d ' ' | wc -w`
  9. while [ $j -le $jmax ]
  10. do
  11. i=1
  12. imax=`head -n$j $1 | tail -n1 | wc -w`
  13. while [ $i -le $imax ]
  14. do
  15. szam=`head -n$j $1 | tail -n1 | tr -s ' ' | cut -f$i -d' '`
  16. szam=$((szam % 2))
  17. if [ $szam -eq 0 ] && [ `expr $j % 2` -eq 0 ]
  18. then
  19. szam=`head -n$j $1 | tail -n1 | tr -s ' ' | cut -f$i -d' '`
  20. psps=`expr $psps + $szam`
  21. elif [ $szam -eq 1 ] && [ `expr $j % 2` -eq 1 ]
  22. then
  23. szam=`head -n$j $1 | tail -n1 | tr -s ' ' | cut -f$i -d' '`
  24. plpl=`expr $plpl + $szam`
  25. elif [ $szam -eq 0 ] && [ `expr $j % 2` -eq 1 ]
  26. then
  27. szam=`head -n$j $1 | tail -n1 | tr -s ' ' | cut -f$i -d' '`
  28. plps=`expr $plps + $szam`
  29. elif [ $szam -eq 1 ] && [ `expr $j % 2` -eq 0 ]
  30. then
  31. szam=`head -n$j $1 | tail -n1 | tr -s ' ' | cut -f$i -d' '`
  32. pspl=`expr $pspl + $szam`
  33. fi
  34. i=`expr $i + 1`
  35. done
  36. j=`expr $j + 1`
  37. done
  38. echo "Páros sorok páros számok összege: $psps"
  39. echo "Páros sorok páratlan számok összege: $pspl"
  40. echo "Páratlan sorok páros számok összege: $plps"
  41. echo "Páratlan sorok páratlan számok összeg: $plpl"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement