Add isEven exercise

After spending so much time having to do bash exercises, writing just
this tiny bit of Go feels incredible
This commit is contained in:
raul 2025-02-03 13:52:04 +01:00
parent 73413b465b
commit 36e2592e4b
Signed by: raul
GPG Key ID: C1AA797073F17129
2 changed files with 37 additions and 0 deletions

3
isEven/go.mod Normal file
View File

@ -0,0 +1,3 @@
module isEven
go 1.23.4

34
isEven/main.go Normal file
View File

@ -0,0 +1,34 @@
package main
import (
"fmt"
"log"
"os"
"strconv"
)
func main() {
if len(os.Args) != 2 {
fmt.Printf("Insufficent arguments:\n")
fmt.Printf("Usage: ./isEven 5\n")
os.Exit(0)
}
num, err := strconv.Atoi(os.Args[1])
if err != nil {
log.Fatalf("Invalid number found: %v\n", err)
}
if s := isEven(num); s == true {
fmt.Printf("El número %v es par\n", num)
} else {
fmt.Printf("El número %v es impar\n", num)
}
}
func isEven(n int) bool {
if n%2 == 0 {
return true
} else {
return false
}
}