I need to do the summation from i = 1 to n of i ^ n in Haskell. Anyone have an idea or can you help me do it? I'm doing a project and I need that in haskell that I do not have much idea.
I need to do the summation from i = 1 to n of i ^ n in Haskell. Anyone have an idea or can you help me do it? I'm doing a project and I need that in haskell that I do not have much idea.
Good evening, a possible solution is this:
sumtoria i n | i==n = i**n
|otherwise = i**n + sumtoria (i+1) n
When i = n makes the power, in the other cases it accumulates the powers while i increases. It is only contemplated by entering values of i less than n. A more elegant solution could be using higher order functions, but that's another topic.
The simplest way:
sumatoria :: Integer -> Integer
sumatoria n = sum [ i^n | i <- [1..n]]
Good morning a possible answer for your serious problem
suma a b | a==b = a**b|otherwise = a**b + suma (a+1) b
Main
suma (2,3)
I hope you serve