这是EDX里Edx-LouvainX: Louv1.01x Paradigms of Computer Programming课程的练习,我正在学习这个课程以娱乐,节选了自己的练习题共分享学习.
编程环境:Mozart2
1.communication vase
You are asked to use an accumulator to compute the sum of the square of the n first integers. Here is the invariant:
sum(n) = sum(i) + acc
For sum(n), your answer has to be: Sum = 1^2 + 2^2 + 3^2 + ... + n^2
SUM
(1/1 point)
Consider your code in the following template:
fun {MainSum N} local Sum in fun {Sum N Acc} [YOUR CODE] end {Sum N 0} end end
correct answer:
if N==0 then Acc
elseif N>0 then M A in
M=N-1
A=N*N+Acc
{Sum M A}
end