Swift Program: Even or Odd Checker

Code (Terminal Input)

import Foundation print("Enter a number: ", terminator: "") if let input = readLine(), let num = Int(input) { if num % 2 == 0 { print("The number is Even.") } else { print("The number is Odd.") } } else { print("Invalid input!") }

Input

Enter a number: 17

Output

The number is Odd.

Code (Assigned Value)

import Foundation let num = 10 if num % 2 == 0 { print("The number is Even.") } else { print("The number is Odd.") }

Input

Value Assigned: 10

Output

The number is Even.
Home