Skip to content

Commit

Permalink
Find sum of even numbers and product of odd numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurwrls committed Oct 8, 2022
1 parent 00d9e75 commit b942551
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//Find sum of even numbers and product of odd numbers

var list = [2, 4, 3, 6, 1, 9]

var sumOfEven = 0
var productOfOdd = 1

for num in list {
if num % 2 == 0 {
sumOfEven += num
} else {
productOfOdd *= num
}
}

print("Sum of even numbers is \(sumOfEven)")
print("Product of odd numbers is \(productOfOdd)")

0 comments on commit b942551

Please sign in to comment.