#include <iostream>
#include <vector>
usingnamespace std;
vector<int>prime;
bool is_prime(int n)
{
for (int p = 0; p<prime.size(); ++p)
{
if (n%prime[p]==0) returnfalse; // no remainder: prime[p] divided
returntrue; // no smaller prime could divide
}
}
int main()
{
try
{
prime.push_back(2); // consider the smallest prime
for (int i = 3; i<=100; ++i) // test all integers [3:100]
if (is_prime(i)) { prime.push_back(i); } // add new prime to vector
cout << "Primes: ";
for (int p = 0; p<prime.size(); ++p)
{ cout << prime[p] << '\n'; }
}
}
Error messages:
1 2 3 4 5 6 7 8 9 10
Documents/Program25.cpp: In function ‘int main()’:
Documents/Program25.cpp:40:1: error: expected ‘catch’ before ‘}’ token
}
^
Documents/Program25.cpp:40:1: error: expected ‘(’ before ‘}’ token
Documents/Program25.cpp:40:1: error: expected type-specifier before ‘}’ token
Documents/Program25.cpp:40:1: error: expected ‘)’ before ‘}’ token
Documents/Program25.cpp:40:1: error: expected ‘{’ before ‘}’ token