Created
April 17, 2016 19:16
-
-
Save kiichi/7fc2b33a0e1da2caed6fcb413e50f505 to your computer and use it in GitHub Desktop.
Find all divisors of the number.
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
//: 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