Created
September 1, 2017 22:39
-
-
Save MatthaeusHarris/dc63a529a7ce62db0cc38d9ee5cad3e4 to your computer and use it in GitHub Desktop.
Fizzbuzz no conditionals
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
#include <stdio.h> | |
char *fizz[3] = {"Fizz", "", ""}; | |
char *buzz[5] = {"Buzz", "", "", "", ""}; | |
void main(void) { | |
for (int i = 1; i <= 100; i++) | |
printf("%d\r%s%s\n", i, fizz[i%3], buzz[i%5]); | |
} |
#include <stdio.h>
#include <string.h>
int fb[8] = {1,0,0,2,0,0,0,0};
void main(void) {
char num[4];
char *fizz = "Fizz";
char *buzz = "Buzz";
char *fizzbuzz = "FizzBuzz";
char *words[4];
words[0] = num;
words[1] = fizz;
words[2] = buzz;
words[3] = fizzbuzz;
int i;
for (i = 1; i <= 100; i++) {
sprintf(words[0], "%d", i);
printf("%s\n", words[fb[i%3] + fb[i%5 + 3]]);
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#include <stdio.h>
int fb[8] = [1,0,0,2,0,0,0]
char *words[4] = {"", "fizz", "buzz", "fizzbuzz"};
void main(void) {
for (i = 1; i <= 100; i++)
words[0] = itoa(i);
printf("%s\n", words[fb[i%3] + fb[i%5 + 3]]);
}