Quote callback:
Write a program to print the numbers 1 to 100. However, when the number is a multiple of 3, "fizz" is printed to replace the number, and "Buzz" is used to replace the number of 5, which is both a multiple of 3 and a multiple of 5 to print "fizzbuzz ".
# Include <stdio. h> # include <stdlib. h> int main () {int I; int Step3 = 1, step5 = 1;/* step count */INT fizzstat = 0, buzzstat = 0, fizzbuzzstat = 0; for (I = 1; I <= 100; I ++) {If (3 = Step3) & (5 = step5) {printf ("% d: fizzbuzz \ n ", I); Step3 = 1; step5 = 1; fizzstat ++; buzzstat ++; fizzbuzzstat ++;} else if (3 = Step3) {printf ("% d: fizz \ n", I); Step3 = 1; step5 ++; fizzstat ++;} else if (5 = step5) {printf ("% d: Buzz \ n", I); Step3 ++; step5 = 1; buzzstat ++;} else {printf ("% d: not fizz buzz \ n ", I); Step3 ++; step5 ++ ;}} printf (" Total fizz = % d, total buzz = % d, total fizzbuzz = % d \ n ", fizzstat, buzzstat, fizzbuzzstat); Return 0 ;}
The step count is used to replace multiple remainder operations on each number. The statistical result of the program is: Total fizz = 33, total buzz = 20, and total fizzbuzz = 6.
Today, I happened to see the "fizzbuzz" question. The above is my little thought. You are welcome to discuss it.