Q: Write a program which will print all the pairs of prime numbers whose sum equals the number entered by the user.
My program is able to find the prime numbers until an integer value, n, and outputs it correctly.
Now how do I find the pairs of prime numbers that add up to n.
Any ideas? Should I use arrays?
Here is my code so far.
//Write a program which will print all the pairs of prime numbers whose sum equals the
//number entered by the user. ( suggested by Aniseed ) (Intermediate)
#include <iostream>
using namespace std;
void PrimeNumbers(int n, int count);
int main(){
int n = 0;
int count =0;
int limit =0;
cout << "Enter an integer:" << endl;
cin >> limit;
for(int n=1; n <= limit; n++){
PrimeNumbers(n,count);
}
cin.get();
cin.get();
}
void PrimeNumbers(int n, int count){
for(int i =1; i <= n; i++){
if(n%i==0){
count ++;
}
}
if(count == 2){
cout << n << " ";
}
}