Last active
February 18, 2021 22:25
-
-
Save mick-io/6514a2cd4176327ee45f3d0d258b4b79 to your computer and use it in GitHub Desktop.
FizzBuzz solved using a variety of programming languages
This file contains hidden or 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
#include <stdio.h> | |
#include <string.h> | |
void fizzbuzz() | |
{ | |
for (int i = 1; i < 101; i++) | |
{ | |
char s[9] = ""; | |
if (i % 3 == 0) | |
{ | |
strcat(s, "Fizz"); | |
} | |
if (i % 5 == 0) | |
{ | |
strcat(s, "Buzz"); | |
} | |
s[0] == '\0' ? printf("%d\n", i) : printf("%s\n", s); | |
} | |
} | |
int main() | |
{ | |
fizzbuzz(); | |
return 0; | |
} | |
// I don't know C, tell me a better way. |
This file contains hidden or 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
package main | |
import "fmt" | |
func main() { | |
fizzbuzz() | |
} | |
func fizzbuzz() { | |
for n := 1; n < 101; n++ { | |
s := "" | |
if n%3 == 0 { | |
s += "Fizz" | |
} | |
if n%5 == 0 { | |
s += "Buzz" | |
} | |
if s != "" { | |
fmt.Println(s) | |
} else { | |
fmt.Println(n) | |
} | |
} | |
} |
This file contains hidden or 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
class Sandbox { | |
public static void main(String[] args) { | |
fizzbuzz(); | |
} | |
private static void fizzbuzz() { | |
for (int n = 1; n < 101; n++) { | |
String s = ""; | |
if (n % 3 == 0) { | |
s += "Fizz"; | |
} | |
if (n % 5 == 0) { | |
s += "Buzz"; | |
} | |
System.out.println(s == "" ? n : s); | |
} | |
} | |
} |
This file contains hidden or 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
#!/usr/bin/env node | |
function fizzbuzz() { | |
for (let n = 0; n < 101; n++) { | |
let s = ""; | |
if (n % 3 === 0) { | |
s += "Fizz"; | |
} | |
if (n % 5 === 0) { | |
s += "Buzz"; | |
} | |
console.log(s || n); | |
} | |
} | |
fizzbuzz(); |
This file contains hidden or 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
#!/usr/bin/env python3 | |
def fizzbuzz(): | |
for n in range(1, 101): | |
out = "" | |
if n % 3 == 0: | |
out += "Fizz" | |
if n % 5 == 0: | |
out += "Buzz" | |
print(out or n) | |
fizzbuzz() |
This file contains hidden or 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
#!/usr/bin/env ruby | |
def fizzbuzz | |
1.upto 100 do |n| | |
s = "" | |
s += "Fizz" if n % 3 == 0 | |
s += "Buzz" if n % 5 == 0 | |
puts s != "" ? s : n | |
end | |
end | |
fizzbuzz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment