Question: Write a Kotlin program to calculate the average using arrays and loops: Solution: fun main ( args: Array ) { / / declaring an array

Write a Kotlin program to calculate the average using arrays and loops:
Solution:
fun main(args: Array){
// declaring an array of doubles using initial values
val myArray= doubleArrayOf(27.60,73.25,-64.50,20.33,38.75,95.87,65.44,11.89)
var sum=0.0
for (i in myArray){
sum +=i
}
val average=sum/myArray.size
println("The average is: %.2f".format(average))
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!