Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <vector>
- using namespace std;
- void Eratos(int length, vector<int>&);
- void print(const vector<int>&);
- int main()
- {
- cout << "Enter a number from 2 to 300 to see all the prime numbers in between: ";
- int range;
- cin >> range;
- if (range >= 2 && range <= 300)
- {
- vector <int> v;
- cout << "Primes between 2 and " << range << ":" << endl;
- Eratos(range, v);
- print(v);
- }
- else
- {
- cout << "ERROR: Number must be from 2 to 300. Exiting program..." << endl;
- }
- return 0;
- }
- void Eratos(int length, vector<int>&v)
- {
- for(int i = 2; i <= length; ++i)
- {
- v.push_back(i);
- }
- // Stumped here...
- }
- void print(const vector<int> &v)
- {
- for(unsigned int i = 0; i < v.size(); ++i)
- {
- cout << setw(5) << v[i];
- if(i % 10 == 0)
- {
- cout << endl;
- }
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement