Advertisement
naskedvi

S2 - zad.24

Mar 15th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4.  
  5. std:: vector<int> prosti_faktori(int n)
  6. {
  7. std:: vector<int>v;
  8. v.push_back(1);
  9. while(n!=1)
  10. {
  11. for(int i=2; i<=n; i++)
  12. {
  13. if(n%i==0)
  14. {
  15. v.push_back(i);
  16. n=n/i;
  17. break;
  18. }
  19. else continue;
  20. }
  21. }
  22. return v;
  23. }
  24.  
  25. int main()
  26. {
  27. int n;
  28. std:: cout << "Unesite broj: ";
  29. std:: cin >> n;
  30.  
  31. std::vector<int> v(prosti_faktori(n));
  32. std::cout << "Prosti faktori su: ";
  33. for(int x : v)
  34. std::cout << x << " ";
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement