Sum and product of an array: Difference between revisions
Content added Content deleted
(Added Kotlin) |
|||
Line 1,198: | Line 1,198: | ||
It is easy to see the relationship of K to J here. |
It is easy to see the relationship of K to J here. |
||
=={{header|Kotlin}}== |
|||
<lang scala>// version 1.1.1 |
|||
fun main(args: Array<String>) { |
|||
val a = intArrayOf(1, 5, 8, 11, 15) |
|||
println("Array contains : ${a.contentToString()}") |
|||
val sum = a.sum() |
|||
println("Sum is $sum") |
|||
val product = a.fold(1) { acc, i -> acc * i } |
|||
println("Product is $product") |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
Array contains : [1, 5, 8, 11, 15] |
|||
Sum is 40 |
|||
Product is 6600 |
|||
</pre> |
|||
=={{header|Lang5}}== |
=={{header|Lang5}}== |