Skip to content

Commit 95b9757

Browse files
dsdsharmaMadhavBahl
authored andcommitted
FizzBuzz in C++ (#8)
* FizzBuzz added in C++ * Rename FizzBuzz.cpp.txt to FizzBuzz.cpp * updated Readme.md
1 parent a5b7bf4 commit 95b9757

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

Day1/C++/FizzBuzz.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @author dsdsharma
3+
* @date 20/12/2018
4+
*/
5+
6+
#include <iostream>
7+
8+
using namespace std;
9+
10+
int main()
11+
{
12+
int n;
13+
cout << "====Fizz Buzz ====" << endl;
14+
cout << "Enter the number: ";
15+
cin >> n;
16+
for(int i=1; i<=n; i++){
17+
if(i%5==0 && i%3==0){
18+
cout << "FizzBuzz ";
19+
}else if(i%3==0){
20+
cout << "Fizz ";
21+
}else if(i%5==0){
22+
cout << "Buzz ";
23+
}else{
24+
cout << i << " ";
25+
}
26+
27+
}
28+
29+
return 0;
30+
}

Day1/README.md

+36
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,39 @@ for i in range(1, n):
172172
print(i)
173173
```
174174
175+
## C++ Implementation
176+
177+
### [FizzBuzz.cpp](./C++/FizzBuzz.cpp)
178+
179+
```c
180+
'''
181+
* @author: Deepak Sharma
182+
* @github: https://github.com/dsdsharma
183+
* @date: 20/12/2018
184+
'''
185+
#include <iostream>
186+
187+
using namespace std;
188+
189+
int main()
190+
{
191+
int n;
192+
cout << "====Fizz Buzz ====" << endl;
193+
cout << "Enter the number: ";
194+
cin >> n;
195+
for(int i=1; i<=n; i++){
196+
if(i%5==0 && i%3==0){
197+
cout << "FizzBuzz ";
198+
}else if(i%3==0){
199+
cout << "Fizz ";
200+
}else if(i%5==0){
201+
cout << "Buzz ";
202+
}else{
203+
cout << i << " ";
204+
}
205+
206+
}
207+
208+
return 0;
209+
}
210+
```

0 commit comments

Comments
 (0)