Created
January 30, 2018 01:14
-
-
Save chandler767/3887687211558f147fb535fd44b4e6e5 to your computer and use it in GitHub Desktop.
Function to determine if a number is prime in Go.
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" | |
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