answer 23 and 25 You rolled 3 2 5 int is 5 2 5 7 Nou rolled you lose 6.23 (Enirp
ID: 3557664 • Letter: A
Question
answer 23 and 25
You rolled 3 2 5 int is 5 2 5 7 Nou rolled you lose 6.23 (Enirp) An emirp (prime spelled backward) is a nonpalindromic prime number whose reversal is also a prime. For example, 17 is a prime and 71 is a prime. So 17 and 71 are emirps. Write a program that displays the first 100 emirps. Display Fin 10 numbers per line and align the numbers properly, as follows: 13 17 31 37 71 73 79 97 107 113 149 157 167 179 199 311 337 347 359 389 "6.24 (Game: chance of winning at craps) Revise Programming Exercise 622 to run it 10000 times and display the number of winning games. 6.25 (Mersenne prime) A prime number is called a Mersenne prime if it can be written in the form of 2 1 for some positive integer p. te a program that finds all Mersenne primes with p si 31 and displays the output as follows:Explanation / Answer
C++ code
#include <iostream>
#include <fstream>
using namespace std;
void reverse ();
bool isPrime;
int main()
{
// variables
int rev_numb;
int digit_1;
int digit_10;
int digit_100;
int digit_1000;
int numb;
// bool isPrime ();
for (int numb=1; numb<=10; numb++)
{
// check if prime
isPrime=true;
if (numb%2 == 0)
{
isPrime=false;
}
else
{
for (int i=3; i<=numb/2; i=i+2)
{
if (numb%i == 0)
{
isPrime=false;
break;
}
}
}
// print if number is prime
if (isPrime)
{
reverse ();
cout << numb << " ";
}
}
// save the number
//bool isPrime=numb;
// strip out the digits
digit_1=numb % 10;
numb=numb / 10;
digit_10=numb % 10;
numb=numb / 10;
digit_100=numb %10;
numb=numb / 10;
digit_1000=numb;
// reverse the number
rev_numb=(digit_1*1000)+(digit_10*100)+(digit_100*10)
+(digit_1000);
// print out the reversed number
cout << "the number reversed = " << rev_numb << " ";
// test to see if it is a palidrome
if (numb == rev_numb)
{
cout << "It is a palidrome.";
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.