-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_multiline_func.cpp
More file actions
43 lines (36 loc) · 1017 Bytes
/
lambda_multiline_func.cpp
File metadata and controls
43 lines (36 loc) · 1017 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
40
41
42
43
//
// Created by zing on 6/30/2020.
//
/* lambda_multiline_func.cpp */
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
auto main() -> int {
cout << "[lambda_multiline_func.cpp]" << endl;
// Initializing a vector containing integer element
vector<int> vect;
vect.reserve(10);
for (int i = 0; i < 10; ++i)
vect.push_back(i);
// Displaying whether or not the element is prime number
for_each(
begin(vect),
end(vect),
[](int n) {
cout << n << " is";
if (n < 2) {
if (n == 0)
cout << " not";
} else {
for (int j = 2; j < n; ++j) {
if (n % j == 0) {
cout << " not";
break;
}
}
}
cout << " prime number" << endl;
});
return 0;
}