#include <stdio.h>
void fizzbuzz(int num_fizz, int num_buzz, int num_fizzbuzz, int counter)
{
if(num_fizzbuzz == 15)
{
printf("fizzbuzz ");
num_fizz=0; num_buzz=0; num_fizzbuzz=0;
}
else if(num_fizz == 3)
{
printf("fizz "); num_fizz=0;
}
else if(num_buzz == 5)
{
printf("buzz "); num_buzz=0;
}
else printf("%d ", counter);
if (counter < 100)
fizzbuzz(++num_fizz, ++num_buzz, ++num_fizzbuzz, ++counter);
}
int main ()
{
fizzbuzz(1,1,1,1);
return 0;
}
FizzBuzz without Mod
Page 1 of 15 Replies - 4007 Views - Last Post: 27 August 2012 - 11:53 AM
#1
FizzBuzz without Mod
Posted 27 August 2012 - 11:30 AM
I recently looked up how to do the FizzBuzz output without modular division. This code works, but I can't seem to understand how it works. Can someone tell me whats going on here?
Replies To: FizzBuzz without Mod
#2
Re: FizzBuzz without Mod
Posted 27 August 2012 - 11:38 AM
I think I see it now. Pretty much resetting to zero everytime and then incrementing the counter. So it counts to 3 and fizzes, resets back to zero and fizzes in another 3 increments. so on and so on
#3
Re: FizzBuzz without Mod
Posted 27 August 2012 - 11:39 AM
Step through it. It's pretty obvious when you run it in your head, or do it with a piece of paper.
What happens on the first round through? The second? The third?
EDIT: Yep, you got it. Cute, huh?
What happens on the first round through? The second? The third?
EDIT: Yep, you got it. Cute, huh?
This post has been edited by jon.kiparsky: 27 August 2012 - 11:39 AM
#4
Re: FizzBuzz without Mod
Posted 27 August 2012 - 11:39 AM
I'd delete this but I don't know how. Feel free too Mr. Mod
#5
Re: FizzBuzz without Mod
Posted 27 August 2012 - 11:46 AM
We don't delete topics here.
#6
Re: FizzBuzz without Mod
Posted 27 August 2012 - 11:53 AM
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote





|