Program in Go language to Calculate Standard Deviation using Math package
Simple program using Pow and Sqrt functions of Math package to calculate Standard Deviation of 10 numbers
Example
// Golang Program to Calculate Standard Deviation
package main
import (
"fmt"
"math"
)
func main(){
var num[10] float64
var sum,mean,sd float64
fmt.Println("****** Enter 10 elements *******")
for i := 1; i <= 10; i++ {
fmt.Printf("Enter %d element : ",i)
fmt.Scan(&num[i-1])
sum += num[i-1]
}
mean = sum/10;
for j := 0; j < 10; j++ {
// The use of Pow math function func Pow(x, y float64) float64
sd += math.Pow(num[j] - mean, 2)
}
// The use of Sqrt math function func Sqrt(x float64) float64
sd = math.Sqrt(sd/10)
fmt.Println("The Standard Deviation is : ",sd)
}
Output
****** Enter 10 elements *******
Enter 1 element : 3
Enter 2 element : 5
Enter 3 element : 9
Enter 4 element : 1
Enter 5 element : 8
Enter 6 element : 6
Enter 7 element : 58
Enter 8 element : 9
Enter 9 element : 4
Enter 10 element : 10
The Standard Deviation is : 15.8117045254457
Most Helpful This Week
Program in Go language to print Floyd's Triangle
GO Program to Calculate Sum of Natural Numbers Using for.....Loop
GO Program to Generate Fibonacci Sequence Up to a Certain Number
GO Program to find area and circumference of circle
Program in Go language to Program to Add Two Matrix Using Multi-dimensional Arrays
Program in Go language to Calculate Average Using Arrays
GO language program with example of String Compare function
GO Program to Check Whether a Number is Even or Odd
GO language program with an example of Hash Table
How to use struct that is imported from another package?