-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Find sum of even numbers and product of odd numbers
- Loading branch information
arthurwrls
committed
Oct 8, 2022
1 parent
00d9e75
commit b942551
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
Codecademy.playground/Pages/Array Even and Odd.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)") |