Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
FizzBuzz with recursion and no multiplication or division
#include <stdio.h>
#include <stdbool.h>
int addDigitsHex(int num);
void recursiveFizzBuzz(int start, int end);
int main (int argc, char const *argv[]) {
recursiveFizzBuzz(1, 100);
return 0;
int addDigitsHex(int num) {
// Add up each hex digit, resulting in a single hex digit sum
// Ex: 111 => 3
// Ex: FC3 => 1E => F
int workingNum = num;
int accum = 0;
while(workingNum > 0){
int temp = workingNum & 0xF;
accum += temp;
workingNum >>= 4;
if(accum > 0xF){
return addDigitsHex(accum);
return accum;
void recursiveFizzBuzz(int start, int limit) {
if(start <= limit){
//if divisible by 5, If you add up all of the hex digits, it will equal 5, A, or F
case 0x5:
case 0xA:
//if divisible by 3, If you add up all of the hex digits, it will equal 3, 6, 9, C or F
case 0x3:
case 0x6:
case 0x9:
// F is the only intersection between the possibilities of divisible by 3 and 5
case 0xF:
printf("%d\n", start);
recursiveFizzBuzz(++start, limit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment