Last active
July 15, 2019 16:05
-
-
Save basebandit/c34e8d0178762577c170b6ec36bf541b to your computer and use it in GitHub Desktop.
Get all integer prime numbers from 0 to 100
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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