Answer to Question #100877 in C++ for saira

Question #100877
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. Get a number as an input from the user and display all the circular prime number below that number. To solve this question, you are NOT allowed to use any concept that we have not studied in our course so far.
1
Expert's answer
2020-01-03T03:11:03-0500

#include "iostream"

#include <cmath>

using namespace std;


int main()

{

int value;

cout << "Input value >=10 : ";

cin >> value;

if (value < 10 )

{

cout << "Too small." << endl;

return 0;

}

int i;



for (i = 10; i < value; i++)

{

int temp = i;

int check = 0;

int times = 0;

for (int j = 2; j < temp / 2; j++)

{

if (temp%j == 0)

{

check = 1;

break;

}

}

if (check == 1);

else

{

int new_temp = temp;

do

{

times++;

new_temp = new_temp / 10;

} while (new_temp >= 10);

int perm = pow(10, times);

for (int k = 0; k < times; k++)

{

temp = (temp % perm)*10 + temp / perm;

for (int j = 2; j < temp / 2; j++)

{

if (temp%j == 0)

{

check = -1;

break;

}

}

if (check != -1) check++;

}

if (check == times)

{

cout << i << endl;


}

}

}

system("pause");

return 0;

}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS