avukas

Vrati vektor bulova

Apr 18th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include<stdexcept>
  4. #include<iomanip>
  5.  
  6. bool JeLiProst(int n)
  7. {
  8.     for (int i(2); i<n; i++)
  9.     {
  10.         if (n%i ==  0)
  11.             return false;
  12.     }
  13.     return true;
  14. }
  15.  
  16. std::vector<bool> VratiBul(std::vector<int> v)
  17. {
  18.  
  19.     std::vector<bool> novi(v.size());
  20.     for (int i(0); i<v.size(); i++)
  21.     {
  22.         novi[i] = JeLiProst(v[i]);
  23.  
  24.     }
  25.     return novi;
  26. }
  27.  
  28. int main()
  29. {
  30.     int n;
  31.     std::cout<<"Unesi broj elemenata vektora:\n";
  32.     std::cin>>n;
  33.     std::vector<int> v;
  34.     std::cout<<"Unesi clanove vektora:\n";
  35.     for (int i(0); i<n; i++)
  36.     {
  37.         int pom;
  38.         std::cin>>pom;
  39.         v.push_back(pom);
  40.     }
  41.     std::cout<<"\nVektor bulova je :\n";
  42.  
  43.     std::vector<bool> novi = VratiBul(v);
  44.     for (int i(0); i<novi.size(); i++)
  45.         std::cout<<novi[i]<<" ";
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment