fork download
  1. // Please write a program using C++ that prints the integers counting down from 95 to 1.
  2. // If the number is a multiple of 7, instead of the number, print Bizz.
  3. // If the sum of the number with the previous Bizzed number is a multiple of 5, print Fuzz.
  4. // If the number is both a multiple of 7 and its sum with the previous Bizzed number is a multiple of 5,
  5. // print BizzFuzz. This counts as a Bizzed number.
  6.  
  7. #include <stdio.h>
  8.  
  9. int main() {
  10. int lastBizzedNum = 0;
  11. for(int i=95;i>0;i--) {
  12. bool bizz = (i % 7) == 0;
  13. bool fuzz = (i + lastBizzedNum) % 5 == 0;
  14. const char* message = 0;
  15. switch ((bizz?1:0) + (fuzz?2:0)) {
  16. case 3:
  17. message = "BizzFuzz";
  18. lastBizzedNum = i;
  19. break;
  20. case 2:
  21. message = "Fuzz";
  22. break;
  23. case 1:
  24. message = "Bizz";
  25. break;
  26. }
  27. if (message) {
  28. printf("%s\n", message);
  29. } else {
  30. printf("%d\n", i);
  31. }
  32. }
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Fuzz
94
93
92
Bizz
Fuzz
89
88
87
86
Fuzz
Bizz
83
82
81
Fuzz
79
78
Bizz
76
Fuzz
74
73
72
71
BizzFuzz
69
68
67
66
Fuzz
64
Bizz
62
61
Fuzz
59
58
57
Bizz
Fuzz
54
53
52
51
Fuzz
Bizz
48
47
46
Fuzz
44
43
Bizz
41
Fuzz
39
38
37
36
BizzFuzz
34
33
32
31
Fuzz
29
Bizz
27
26
Fuzz
24
23
22
Bizz
Fuzz
19
18
17
16
Fuzz
Bizz
13
12
11
Fuzz
9
8
Bizz
6
Fuzz
4
3
2
1