Advertisement
naskedvi

T3. - zad.2

Mar 17th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4.  
  5. bool prost (int n)
  6. {
  7. for (int i=2;i<n;i++)
  8. {
  9. if (n%i==0)return false;
  10. }
  11. return true;
  12. }
  13.  
  14. int main()
  15. {
  16. std::cout<<"Unesite broj elemenata: ";
  17. int n;
  18. std::cin>>n;
  19. std::vector<int>a(n);
  20. for (int i=0;i<n;i++)
  21. std::cin>>a[i];
  22.  
  23. std::vector<int>b,c;
  24. for (int x: a)
  25. {
  26. if(x==1) continue;
  27. else if (prost(x))
  28. b.push_back(x);
  29. else
  30. c.push_back(x);
  31. }
  32.  
  33. for(int i=0; i<b.size()-1; i++)
  34. std::cout<< b[i] << ",";
  35. std:: cout<<b[b.size()-1];
  36.  
  37. std::cout<<std::endl;
  38.  
  39. for(int i=0; i<c.size()-1; i++)
  40. std::cout<< c[i] << ",";
  41. std:: cout<<c[c.size()-1];
  42. return 0;
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement