Skip to content

Instantly share code, notes, and snippets.

@chandler767
Created January 30, 2018 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chandler767/3887687211558f147fb535fd44b4e6e5 to your computer and use it in GitHub Desktop.
Save chandler767/3887687211558f147fb535fd44b4e6e5 to your computer and use it in GitHub Desktop.
Function to determine if a number is prime in Go.
package main
import "fmt"
func main(){
fmt.Println(isPrime(4))
fmt.Println(isPrime(7))
fmt.Println(isPrime(1616161))
}
/**
* This function should return true if inputNumber is prime (divisible only by itself and 1), false otherwise.
*/
func isPrime(inputNumber int) string{
for i := 2; i <= (inputNumber/2); i++ {
if inputNumber%i == 0 {
return "false"
}
}
return "true"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment