Skip to content

Commit d75e3c4

Browse files
Added 1 Question and added break in loops
1 parent 5aec3e4 commit d75e3c4

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/.vscode
1+
.vscode

Basics/5_LOOPS/while_loops.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ int main() {
1212
++i;
1313
}
1414

15+
cout << endl;
16+
1517
//Ouput:
1618
// 0
1719
// 1
@@ -25,6 +27,20 @@ int main() {
2527
// 9
2628
// 10
2729

30+
//break is a keyword we use when we want to stop the execution of a loop
31+
32+
i = 0; //no need to redefine
33+
34+
while(i <= 10)
35+
{
36+
cout << i << endl;
37+
if(i == 5)
38+
{
39+
break;
40+
}
41+
++i;
42+
}
43+
2844
return 0;
2945
}
3046

Questions/FizzBuzz

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Write a short program that prints each number from 1 to 100 on a new line.
2+
3+
For each multiple of 3, print "Fizz" instead of the number.
4+
5+
For each multiple of 5, print "Buzz" instead of the number.
6+
7+
For numbers which are multiples of both 3 and 5, print "FizzBuzz" instead of the number.
8+
9+
Sample Output:
10+
1
11+
2
12+
Fizz
13+
4
14+
Buzz
15+
Fizz
16+
7
17+
8
18+
Fizz
19+
Buzz
20+
11
21+
Fizz
22+
13
23+
14
24+
FizzBuzz
25+
16
26+
17
27+
Fizz

Solutions/FizzBuzz.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
for (int i = 1; i<=100; ++i)
7+
{
8+
if (i%15 == 0)
9+
{
10+
cout << "FizzBuzz" << endl;
11+
}
12+
13+
else if (i%3 == 0)
14+
{
15+
cout << "Fizz" << endl;
16+
}
17+
18+
else if (i%5 == 0)
19+
{
20+
cout << "Buzz" << endl;
21+
}
22+
23+
else
24+
{
25+
cout << i << endl;
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)