-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunc.cpp
More file actions
56 lines (48 loc) · 1.09 KB
/
func.cpp
File metadata and controls
56 lines (48 loc) · 1.09 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <sequtils.h>
using namespace std;
void print(int elem)
{
cout << elem << ' ';
}
int square(int x) { return x * x; }
int main(int argc, char *argv[])
{
vector<int> col;
set<int> v;
cout << "For each testing " << endl;
for (int i=0; i < 10; i++)
col.push_back(i);
for_each(col.begin(), col.end(), print);
cout << endl;
cout << "transform testing " << endl;
transform(col.begin(), col.end(),
inserter(v, v.end()),
square);
print_seq(v, "after\t");
col.erase(col.begin(), col.end());
v.erase(v.begin(), v.end());
list<int> lst;
for(int i=24; i <= 30; i++) lst.push_back(i);
print_seq(lst, "list\t");
list<int>::iterator pos;
pos = find_if (lst.begin(), lst.end(),
[](int x) {
int i = 2;
while (i < x / 2) {
if ((x % i) == 0) return false;
++i;
}
return true;
});
if (pos != lst.end()) {
cout << "prime number found " << *pos << endl;
} else {
cout << "No prime found in the given range " << endl;
}
return 0;
}