Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int n = 500;
  11.     vector<int> tab;
  12.     vector<int> evenNumbers;
  13.  
  14.     srand(time(NULL));
  15.  
  16.     //losujemy liczby, wyypelniamy tablice
  17.     for(int i=0; i<n; i++){
  18.         int random = rand()% 500;
  19.         tab.push_back(random);
  20.     }
  21.  
  22.     //sprwdzamy cy parzyste, jesli tak dodajemy do nowej tablicy/vectora
  23.     for(auto & element: tab) {
  24.         if(element % 2 == 0) {
  25.             evenNumbers.push_back(element);
  26.         }
  27.     }
  28.  
  29.     //wypisujemy zawartosc tablicy z parzystymi
  30.     cout << "+++++++++++Even numbers:+++++++++++" << endl;
  31.     for(auto & element: evenNumbers) {
  32.         cout<<element<<", ";
  33.     }
  34.  
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement