Skip to content

Instantly share code, notes, and snippets.

@basebandit
Last active July 15, 2019 16:05
Show Gist options
  • Save basebandit/c34e8d0178762577c170b6ec36bf541b to your computer and use it in GitHub Desktop.
Save basebandit/c34e8d0178762577c170b6ec36bf541b to your computer and use it in GitHub Desktop.
Get all integer prime numbers from 0 to 100
package main
import (
"fmt"
"math"
)
func main() {
for i := 0; i < 100; i++ {
if isPrime(i) {
fmt.Printf("%d\n", i)
}
}
}
func isPrime(num int) bool {
for i, n := 2, math.Sqrt(float64(num)); i <= int(n); i++ {
if num%i == 0 {
return false
}
}
return num > 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment