- This program can calculate average of numbers you input.
- A program to run
.kt
with compiler - or a online kotlin compiler and output
- Download the
avg cal.kt
and run it. - or copy the code and paste it on a online compiler and run.
- when changing the numbers,
val numArray = doubleArrayOf(50.0, 67.5, -45.6, 20.34, 33.0, 45.6)
put your numbers except those numbers (code will come up with this numbers.)
fun main(args: Array<String>) {
val numArray = doubleArrayOf(50.0, 67.5, -45.6, 20.34, 33.0, 45.6)
var sum = 0.0
for (num in numArray) {
sum += num
}
val average = sum / numArray.size
println("The average is: %.2f".format(average))
}