suhaib

Download Raw Clone


  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. vector<int> arr;
  6. for (int i = 0; i < 100; ++i)
  7. arr.push_back(i);
  8. for (int i = 2; i * i < 99; ++i)
  9. {
  10. for (int j = 2 * i; j < 101; j += i)
  11. {
  12. arr[j] = 0;
  13. }
  14. }
  15. vector <int> primes;
  16. for (int i = 0; i < 100; i++)
  17. if (arr[i] >= 2) primes.push_back(arr[i]);
  18. for(int i = 0; i < primes.size(); i++)
  19. {
  20. cout << primes[i] << " ";
  21. }
  22. return 0;
  23. }

Raw paste data: