I am a newbie to programming .here I have been solving a simple problem in functional programming (OZ) which is finding the sum of the Digits of a 6 digit positive integer.
Example:- if n = 123456
then
output = 1+2+3+4+5+6 which is 21
.
here I found a solution like below
fun {SumDigits6 N}
{SumDigits (N Div 1000) + SumDigits (N mod 1000)}
end
and it says the argument (N Div 1000)
gives first 3 digits and the argument (N mod 1000)
gives us last 3 digits. and yes I getting the correct solution but my Doubt is how could they giving correct solutions. I mean in given example isn't (N Div 1000) of 123456
gives 123
right not 1+2+3
and similarly (N mod 1000) of123456
gives us 456
not 4+5+6
right ?. in that case, the answer should be 123+456
which is equals to 579
not 21
right ? what Iam missing here.I apologize for asking such simple question but any help would be appreciated.
Thank you :)