/* Go-lang programme to determine the average and median using float32 array*/
package main
import "fmt"
func main(){
var n,flag int
var temp,sumx,avg float32
var a [30]float32
sumx=0
flag=0
fmt.Println("enter the value of n ")
fmt.Scanf("%d",&n)
fmt.Println("enter the numbers")
for i := 0; i < n; i++ {
fmt.Scanf("%f",&a[i])
}
for i := 0; i < n; i++ {
for j := 0; j < (n-1); j++ {
if (a[j] > a[j+1]){
temp=a[j]
a[j]=a[j+1]
a[j+1]=temp
}
}
}
for i := 0; i < n; i++ {
sumx+=a[i]
}
avg=sumx/float32(n)
if (n%2==0) {
flag=1
}
if flag==1 {
fmt.Println("medians are and ",a[(n/2)-1],a[(n/2)])
}
if flag==0 {
fmt.Println("median is ",a[(n/2)])
}
fmt.Println("average is ",avg)
}
Average and median of number list using GO language