Advertisement
amermo

Vrati vektor u kojem su potpuni kvadrati manji od n

Feb 28th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. std::vector<int> PotpuniKvadrati(int n)
  6. {
  7.     std::vector<int> v;
  8.     for(int i(0); i < n; i++)
  9.     {
  10.         if(sqrt(i) == int(sqrt(i)))
  11.             v.push_back(i);
  12.     }
  13.     return v;
  14. }
  15.  
  16. int main()
  17. {
  18.     std::vector<int> test = PotpuniKvadrati(100);
  19.     for(unsigned int i(0); i < test.size(); i++)
  20.         std::cout << test[i] << " ";
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement