fork download
  1. #!/bin/bash
  2.  
  3. f() {
  4. t=0 ;# if this was a standalone program, t is auto initialised to 0
  5.  
  6. # The following lines may be put in a standalone script file and run as is:
  7. b=10
  8. for i;{((t+=$b#$i,b=i));}
  9. echo $t
  10.  
  11. }
  12.  
  13. for testcase in \
  14. "4 12 34 20 14 6 25 13 33" \
  15. "5 14 2 11 30 18" \
  16. "12 11 10 9 8 7 6 5 4 3 12 2 11 3 10 2 10" \
  17. "36 36"
  18. do
  19. f $testcase
  20. done
Success #stdin #stdout 0s 5092KB
stdin
Standard input is empty
stdout
235
90
98
150