Skip to content

Instantly share code, notes, and snippets.

@cuongld2
Created May 20, 2021 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuongld2/5b368fb80bd3c2548875e5886bc6dd1f to your computer and use it in GitHub Desktop.
Save cuongld2/5b368fb80bd3c2548875e5886bc6dd1f to your computer and use it in GitHub Desktop.
recursive sum function in julia
function sum(array)
k=length(array)
if k==0
return 0
end
if k==1
return array[k]
end
return array[k] + sum(array[1:k-1])
end
println(sum([13,2,4,5,6,3]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment