Advertisement
naskedvi

S2 - zad.28

Mar 15th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. std:: vector<int> f(std:: vector<int> v, int n)
  5. {
  6. std:: vector<int>w;
  7. int cifra, suma(0);
  8. for(int x:v)
  9. {
  10. int a(x);
  11. while(x!=0)
  12. {
  13. cifra=x%10;
  14. suma+=cifra;
  15. x=x/10;
  16. }
  17. if(suma>n) w.push_back(a);
  18. suma=0;
  19. }
  20. return w;
  21. }
  22.  
  23. int main()
  24. {
  25. int n, a;
  26.  
  27. std:: cout << "Unesite broj elemenata niza! ";
  28. std:: cin >> n;
  29. std:: vector<int> v(n);
  30. std:: cout << "Unesite elemente niza: ";
  31. for(int i=0; i<n; i++)
  32. std:: cin>> v[i];
  33.  
  34. std:: cout << "Unesite broj: ";
  35. std:: cin >> a;
  36.  
  37. std::vector<int> v1(f(v, a));
  38. std::cout << "Novi vektor glasi: ";
  39. for(int x : v1)
  40. std::cout << x << " ";
  41.  
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement