"checking for prime numbers using golang" Code Answer's
You're definitely familiar with the best coding language Go that developers use to develop their projects and they get all their queries like "checking for prime numbers using golang" answered properly. Developers are finding an appropriate answer about checking for prime numbers using golang related to the Go coding language. By visiting this online portal developers get answers concerning Go codes question like checking for prime numbers using golang. Enter your desired code related query in the search bar and get every piece of information about Go code related question on checking for prime numbers using golang.
checking for prime numbers using golang
package main
import (
"fmt"
"math"
)
func IsPrime(value int) bool {
for i := 2; i <= int(math.Floor(float64(value)/2)); i++ {
if value%i == 0 {
return false
}
}
return value > 1
}
func IsPrimeSqrt(value int) bool {
for i := 2; i <= int(math.Floor(math.Sqrt(float64(value)))); i++ {
if value%i == 0 {
return false
}
}
return value > 1
}
func SieveOfEratosthenes(value int) {
f := make([]bool, value)
for i := 2; i <= int(math.Sqrt(float64(value))); i++ {
if f[i] == false {
for j := i * i; j < value; j += i {
f[j] = true
}
}
}
for i := 2; i < value; i++ {
if f[i] == false {
fmt.Printf("%v ", i)
}
}
fmt.Println("")
}
func main() {
for i := 1; i <= 100; i++ {
if IsPrime(i) {
fmt.Printf("%v ", i)
}
}
fmt.Println("")
for i := 1; i <= 100; i++ {
if IsPrimeSqrt(i) {
fmt.Printf("%v ", i)
}
}
fmt.Println("")
SieveOfEratosthenes(100)
}
Source: www.thepolyglotdeveloper.com
checking for prime numbers using golang
const n = 1212121
if big.NewInt(n).ProbablyPrime(0) {
fmt.Println(n, "is prime")
} else {
fmt.Println(n, "is not prime")
}
Source: yourbasic.org
All those coders who are working on the Go based application and are stuck on checking for prime numbers using golang can get a collection of related answers to their query. Programmers need to enter their query on checking for prime numbers using golang related to Go code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about checking for prime numbers using golang for the programmers working on Go code while coding their module. Coders are also allowed to rectify already present answers of checking for prime numbers using golang while working on the Go language code. Developers can add up suggestions if they deem fit any other answer relating to "checking for prime numbers using golang". Visit this developer's friendly online web community, CodeProZone, and get your queries like checking for prime numbers using golang resolved professionally and stay updated to the latest Go updates.