Created
May 20, 2021 09:10
-
-
Save cuongld2/5b368fb80bd3c2548875e5886bc6dd1f to your computer and use it in GitHub Desktop.
recursive sum function in julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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