From a6a38dd13fe7e7728a50014ecfee7c82b1c66404 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Mon, 26 Jun 2023 14:22:17 +0530 Subject: [PATCH 1/2] Update main.go Added prime number function. --- bundle-server/main.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/bundle-server/main.go b/bundle-server/main.go index 9a08037..3daa57b 100644 --- a/bundle-server/main.go +++ b/bundle-server/main.go @@ -19,8 +19,29 @@ func main() { w.Header().Set("Content-Type", "application/gzip") http.ServeFile(w, r, r.URL.Path[1:]) }) - + printPrimeNumber(5,19) // start HTTP server with `http.DefaultServeMux` handler log.Fatal(http.ListenAndServe(":9000", nil)) } + +func printPrimeNumbers(num1, num2 int){ + if num1<2 || num2<2{ + fmt.Println("Numbers must be greater than 2.") + return + } + for num1 <= num2 { + isPrime := true + for i:=2; i<=int(math.Sqrt(float64(num1))); i++{ + if num1 % i == 0{ + isPrime = false + break + } + } + if isPrime { + fmt.Printf("%d ", num1) + } + num1++ + } + fmt.Println() +} From caade992874222be3c2cc589a88385fdc1ce6d9f Mon Sep 17 00:00:00 2001 From: Gaurav Date: Mon, 26 Jun 2023 15:24:00 +0530 Subject: [PATCH 2/2] Update main.go --- bundle-server/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle-server/main.go b/bundle-server/main.go index 3daa57b..e1475da 100644 --- a/bundle-server/main.go +++ b/bundle-server/main.go @@ -27,7 +27,7 @@ func main() { func printPrimeNumbers(num1, num2 int){ if num1<2 || num2<2{ - fmt.Println("Numbers must be greater than 2.") + fmt.Println("Numbers must be greater than 2 for this to work.") return } for num1 <= num2 { @@ -39,7 +39,7 @@ func printPrimeNumbers(num1, num2 int){ } } if isPrime { - fmt.Printf("%d ", num1) + fmt.Printf("Found Prime number: %d ", num1) } num1++ }