Advertisement
caubert

sumSequence

Feb 18th, 2020
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.48 KB | None | 0 0
  1. {{ $cArgInt := carg "int" "int" }}
  2. {{ $args := parseArgs 3 "Prameters for Sum of Arithmetic Series  a, d, n" $cArgInt $cArgInt $cArgInt }}
  3. {{ $a := $args.Get 0 }} {{ $d := $args.Get 1 }} {{ $n := $args.Get 2 }} {{ $sum := 0 }}
  4.  
  5. {{/* To verify range loop's return we build the formula using math functions */}}
  6. Verification: {{ mult (div $n 2) (add (mult 2 $a) (mult $d (sub $n 1) ) ) -}}
  7.  
  8. {{ range seq 0 $n }} {{ $sum = add $sum $a }} {{ $a = add $a $d }} {{ end }}
  9. Answer: {{ $sum }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement