Created
June 8, 2014 15:35
-
-
Save henry0312/f3e84915e770a47e9b94 to your computer and use it in GitHub Desktop.
FizzBuzz with 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
func FizzBuzz(n: Int) { | |
for i in 1...n { | |
if i % 15 == 0 { | |
println("FizzBuzz") | |
} else if i % 3 == 0 { | |
println("Fizz") | |
} else if i % 5 == 0 { | |
println("Buzz") | |
} else { | |
println(i) | |
} | |
} | |
} | |
if C_ARGC != 2 { | |
println("Wrong arguments") | |
println("Usage: ./fizzbuzz Num") | |
} else { | |
FizzBuzz( String.fromCString(C_ARGV[1]).toInt()! ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment