Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create StandardDeviation.ktm #161

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions StandardDeviation.Kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
fun main(args: Array<String>) {
val numArray = doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0)
val SD = calculateSD(numArray)

System.out.format("Standard Deviation = %.6f", SD)
}

fun calculateSD(numArray: DoubleArray): Double {
var sum = 0.0
var standardDeviation = 0.0

for (num in numArray) {
sum += num
}

val mean = sum / 10

for (num in numArray) {
standardDeviation += Math.pow(num - mean, 2.0)
}

return Math.sqrt(standardDeviation / 10)
}