#include <iostream>
usingnamespace std;
bool isPrime(int value); // Returns true if value is a prime number.
int reverse(int value); // Returns the reverse of the value (i.e. if value is 35, returns 53).
int main(){
int value, count = 0;
do{
cout << "Please enter a positive number: ";
cin >> value;
} while (value < 0);
if (isPrime(value) == 1){
for (int test = 0; test < value; test++){
//prime number reverse?
}
system("pause");
}
bool isPrime(int value){
bool prime;
if (value % 2 == 0 || value % 3 == 0 || value % 5 == 0 || value % 7 == 0){
prime = false;//0
}
else{
prime = true;//1
}
return prime;
}
int reverse(int value){
int rnum = 0;
while (value) {
rnum = rnum * 10 + (value == 10);
value /= 10;
}
return rnum;
}
According to your requirements the user enters the number of primes, i.e. the do while loop on line 11 is wrong.
What you basically have to do is:
- A loop that iterate as long as you haven't found enough primes
- Find a prime
- Create the counter part (e.g. 13 -> 31)
- Check whether the counter part is prime
- Loop until you reach the number of primes the user has entered
the algorithm for finding a prime is as follows:
- A loop that iterates until sqrt(value)
- If you find (value % i) != 0 -> break, no prime
bool isPrime(int value); // Returns true if value is a prime number.
int reverse(int value); // Returns the reverse of the value (i.e. if value is 35, returns 53).
int main()
{
int n, count = 0, i = 1, a = 1;
cout << "Please enter a positive number: ";
cin >> n;