خرید بک لینک

Vote count: 0

I want to code a function in Scala that takes two integers and sums the cube root of every value in the range of those two integers.

For example, I call:

sumCubes(0,2)

I must get the result 9 because (0^3+1^3+2^3) = 9.

I have to use the range method and consider this template:

def sumCubes2(x: Int, y: Int)= {
@aotation.tailrec
def fAux(acc: Int,xs: List[Int]): Int= ???
???
}

I thought about creating a list with the elements in the range of the two integers and another variable that will contain the final result:

var rangeList = List.range(x, y)
var finalValue = 0

Now I don't know if I should use a for loop or call recursively the function fAux somehow.

Can anyone help me?

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 30 فروردين 1395 ساعت: 9:59

صفحه بندی