-
Notifications
You must be signed in to change notification settings - Fork 0
/
fizzbuzz.cc
42 lines (32 loc) · 886 Bytes
/
fizzbuzz.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// "Write a program that prints the numbers from 1 to 100. But for multiples
// of three print “Fizz” instead of the number and for the multiples of five
// print “Buzz”. For numbers which are multiples of both three and five print
// “FizzBuzz”.
#include <iostream>
#include <sstream>
using namespace std ;
int main (
int nNumberofArguments,
char* apszArgument[]
)
{
int nReturncode = 0;
stringstream ssOutputLine ("") ;
int nCount = 1 ;
while ( nCount <= 100) {
if ( ( ( nCount % 3 ) == 0 ) ||
( ( nCount % 5 ) == 0 )
) {
if ( ( nCount % 3 ) == 0 )
ssOutputLine << "Fizz" ;
if ( ( nCount % 5 ) == 0 )
ssOutputLine << "Buzz" ;
}
else
ssOutputLine << nCount ;
cout << ssOutputLine.str() << "\n" ;
ssOutputLine.str("") ;
nCount++ ;
}
return nReturncode ;
}