Section9-complete
This commit is contained in:
@@ -6,16 +6,37 @@ nums := [...]int{30, -1, -6, 90, -6}
|
||||
|
||||
Write a Go program that counts the number of positive even numbers
|
||||
in the array.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
nums := [...]int{30, -1, -6, 90, -6}
|
||||
|
||||
for i := 0; i < len(nums); i++ {
|
||||
if i > 0 && i%2 {
|
||||
|
||||
for i := 0; i < len(nums); {
|
||||
if i%2 == 0 && i > 0 {
|
||||
i++
|
||||
}
|
||||
fmt.Println("No. of positive even numbers in nums: ", i)
|
||||
}
|
||||
}
|
||||
*/
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
nums := []int{30, -1, -6, 90, -6}
|
||||
|
||||
var count int
|
||||
|
||||
for _, v := range nums {
|
||||
if v%2 == 0 && v > 0 {
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("No. of positive even numbers in nums: ", count)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user