Laboratorio 5
O objetivo deste exercício é colocar em prática conceitos de containers, iteradores e algoritmos da STL (StandardTemplateLibrary)nalinguagemdeprogramaçãoC++.
primo.h
1 # ifndef PRIMO_H_
2 # define PRIMO_H_
3 
4 #include <iostream>
5 #include <algorithm>
6 #include <cmath>
7 
8 using std::cout;
9 using std::endl;
10 using std::cin;
11 using std::vector;
12 
14 bool is_prime( int k)
15 {
16  int i;;
17  int cont = 0;
18  if( k == 1)
19  {
20  return true;
21  }
22  else
23  {
24  for (i = 1; i <= k; i++)
25  {
26  if ( k % i == 0)
27  {
28  cont++;
29  }
30  }
31  if( cont == 2)
32  {
33  return true;
34  }
35  }
36  return false;
37 }
38 
40 template<typename It>
41 void find_prime(It first, It last)
42 {
43 
44  cout<<endl;
45  cout<<" Numeros primos ["<<*(first)<<"-"<<*(last-1)<<"]: ";
46  for (auto i = first; i != last; ++i)
47  {
48  auto it = find_if(i, last, is_prime);
49  if( *i == *it)
50  {
51  cout<<*it<<" ";
52  }
53  }
54  cout<<endl<<endl;
55 
56 }
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 # endif