I need your help in this program, this would very important for me. Find the first 10 prime numbers, which the following formula applies:
prime + 10 = prime number
prime + 14 = prime number
(prime)² + 2 = prime number
So to make the task cleaner,the first prime number will be the 3,because
3+10 = 13 (13 is a prime number)
3+14 = 17 (17 is a prime number)
3²+2 = 11 (11 is a prime number)
I have no idea,how should I make these statements in the program. I've done it so far. The "2" is missing, but I think its not problem, because it won't be in any of these condition.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <iostream>
using namespace std;
int main() {
int num, i,counter=0;
cout << endl << "The first 10 prime numbers are : " << endl;
for(num = 2; num <= 100000; num++) {
for(i = 2; i <= (num / 2); i++) {
if(num % i == 0) {
i = num;
break;
}
}
if(i != num) {
counter=counter + 1;
cout << num << " ";
}
if(counter > 9)
{
system("pause");
}
}
}
| |