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 <iostream>
  8. using namespace std;
  9.  
  10. int main(int argc, char** argv) {
  11. int lastBizz = 0;
  12.  
  13. for ( int i = 95; i >= 1; i-- ) {
  14. bool shouldBizz = false, shouldFuzz = false;
  15.  
  16. shouldBizz = ( i % 7 ) == 0;
  17. shouldFuzz = lastBizz != 0 && ( ( lastBizz + i ) % 5 == 0 );
  18.  
  19. if ( shouldBizz ) lastBizz = i;
  20.  
  21. if ( shouldBizz && shouldFuzz )
  22. cout << "BizzFuzz" << endl;
  23. else if ( shouldBizz )
  24. cout << "Bizz" << endl;
  25. else if ( shouldFuzz )
  26. cout << "Fuzz" << endl;
  27. else
  28. cout << i << endl;
  29. }
  30. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
95
94
93
92
Bizz
90
Fuzz
88
87
86
85
BizzFuzz
83
82
Fuzz
80
79
78
Bizz
76
75
74
Fuzz
72
71
Bizz
69
68
67
66
Fuzz
64
Bizz
Fuzz
61
60
59
58
Fuzz
Bizz
55
Fuzz
53
52
51
50
BizzFuzz
48
47
Fuzz
45
44
43
Bizz
41
40
39
Fuzz
37
36
Bizz
34
33
32
31
Fuzz
29
Bizz
Fuzz
26
25
24
23
Fuzz
Bizz
20
Fuzz
18
17
16
15
BizzFuzz
13
12
Fuzz
10
9
8
Bizz
6
5
4
Fuzz
2
1