-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha1_fizzbuzz.cpp
More file actions
40 lines (34 loc) · 844 Bytes
/
a1_fizzbuzz.cpp
File metadata and controls
40 lines (34 loc) · 844 Bytes
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
#include <iostream>
#include <string>
#include <thread>
int main()
{
auto fizzbuzz = [](size_t epoch) -> void {
const size_t num{4};
const std::string names[num] = {"Abdul", "Bart", "Claudia", "Divya"};
for (size_t i = 1; i <= epoch; ++i)
{
std::cout << names[(i-1) % num] << " says ";
if (i % 3 == 0 && i % 5 == 0)
{
std::cout << "fizzbuzz!";
}
else if (i % 3 == 0)
{
std::cout << "fizz!";
}
else if (i % 5 == 0)
{
std::cout << "buzz!";
}
else
{
std::cout << i;
}
std::cout << std::endl;
}
};
std::thread t{fizzbuzz, 100};
t.join();
return 0;
}