Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute GO Language Online

package main

import ("fmt"
    "math/rand"
)

const NUMS = 100
var num [NUMS] int

func gen_nums() {
    rand.Seed(183)
    for count := 0; count < NUMS; count++ {
        num[count] = rand.Intn(10000)
    }
}

func swap(x *int, y *int) {
    temp := *x
    *x = *y
    *y = temp
}

func main() {
    gen_nums()
    for count1 := 0; count1 < NUMS - 1; count1++ {
        for count2 := count1 + 1; count2 < NUMS; count2++ {
            if num[count1] > num[count2] {
                swap(&num[count1], &num[count2])
            }
        }
    }
    
    for count := 0; count < NUMS; count++ {
        fmt.Printf("%d\n", num[count])
    }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.