Skip to content

Instantly share code, notes, and snippets.

@kiichi
Created April 17, 2016 19:16
Show Gist options
  • Save kiichi/7fc2b33a0e1da2caed6fcb413e50f505 to your computer and use it in GitHub Desktop.
Save kiichi/7fc2b33a0e1da2caed6fcb413e50f505 to your computer and use it in GitHub Desktop.
Find all divisors of the number.
//: c - Algorithm to find all the exact divisors of a given integer - Stack Overflow : http://stackoverflow.com/questions/11699324/algorithm-to-find-all-the-exact-divisors-of-a-given-integer
import Cocoa
func printDivisors(x:Int){
let sqr = sqrt(Double(x))
for i in 2..<Int(sqr)+1 {
if x % i == 0 {
print(i)
if i != (x/i) {
print((x/i))
}
}
}
}
printDivisors(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment