Advertisement
naskedvi

S2 - zad.29

Mar 15th, 2014
145
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. std:: vector<double> f(std:: vector<double> v)
  5. {
  6. std:: vector<double>w;
  7. for(int i=0; i<v.size(); i++)
  8. {
  9. if(v[i]>v[i+1] && v[i]>v[i-1])
  10. w.push_back(v[i]);
  11. }
  12. return w;
  13. }
  14.  
  15. int main()
  16. {
  17. int n;
  18.  
  19. std:: cout << "Unesite broj elemenata niza! ";
  20. std:: cin >> n;
  21. std:: vector<double> v(n);
  22. std:: cout << "Unesite elemente niza: ";
  23. for(int i=0; i<n; i++)
  24. std:: cin>> v[i];
  25.  
  26. std::vector<double> v1(f(v));
  27. std::cout << "Novi vektor glasi: ";
  28. for(double x : v1)
  29. std::cout << x << " ";
  30.  
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement