Skip to content

Commit

Permalink
Merge pull request #727 from andrideng/master
Browse files Browse the repository at this point in the history
fix beginner problem 2 using golang
  • Loading branch information
TANIYA GUPTA authored Oct 29, 2018
2 parents d919de8 + faa2ecc commit 030b7f1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
36 changes: 36 additions & 0 deletions SOLUTIONS/BeginnerProblem2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import "fmt"

func main() {
// - input number of iteration
I := 0
fmt.Scanf("%d", &I)
for i := 0; i < I; i++ {
fmt.Printf("Iteration#%d\n", i+1)
N := 0
arr := []int{}
fmt.Scanf("%d", &N)

// - input number to check
for j := 0; j < N; j++ {
tmp := 0
fmt.Scanf("%d", &tmp)
arr = append(arr, tmp)
}
// - print out result
res := divBy2(arr)
fmt.Printf("Output#%d: %d\n\n", (i + 1), res)
}

}

func divBy2(arr []int) (counter int) {
for i := 0; i < len(arr); i++ {
if arr[i]%2 == 0 {
counter++
}
}

return
}
26 changes: 26 additions & 0 deletions SOLUTIONS/FizzBuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import "fmt"

func main() {
I := 0
fmt.Scanf("%d", &I)
for i := 0; i < I; i++ {
fmt.Printf("Iteration#%d\n", i+1)
N := 0
fmt.Scanf("%d", &N)

for n := 1; n <= N; n++ {
if n%3 == 0 && n%5 == 0 {
fmt.Println("FizzBuzz")
} else if n%3 == 0 {
fmt.Println("Fizz")
} else if n%5 == 0 {
fmt.Println("Buzz")
} else {
fmt.Println(n)
}
}
}

}

0 comments on commit 030b7f1

Please sign in to comment.