main.swift475 chars22 lines
The checkIfNumberIsPrime
function returns a boolean value that indicates if the given number is prime or not. The function checks for numbers that are less than the given number, starting from 2, and if any of them divide the number exactly, the function returns false
.
The printListFactors
function prints a list of all factors of the given number. We loop through all numbers that are less than half the given number and check if the number is divisible by that value. If it is, we print that value as a factor.
You can call these functions like this:
main.swift181 chars9 lines
This would output:
main.swift12 chars2 lines
gistlibby LogSnag