Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a for loop to compute and display the number of prime twinpairs less than

ID: 3618573 • Letter: W

Question

Write a for loop to compute and display the number of prime twinpairs less than integer n, where n is a number you read fromkeyboard. For n = 10, this number should be 2 since {3, 5} and {5,7} are two prime twin pairs less than 10.
Test your program with n = 100, n = 1000, and an integer n providedby you between 500 and 5000 other than 1000. For the third integern, make sure your programs prompts again for n = 499, n = 5001 andthen a good integer between 500 and 5000 provided by you.
Enhance your program to add one prompt “Do you want to printout all the prime twin pairs?”
If the answer is “No”, your program prints out thetotal number of prime twins less than n.
If the answer is “Yes”, your program will print out upto two pairs of prime twins per line like below:
{2, 3} {5, 7}
{11, 13} {17, 19}

Explanation / Answer

//Hope this will helpyou.
#include<iostream> using namespace std;
int main() {    int n,i,j,m=2,p1,p2,count=0;    cout<<"Enter n";    cin>>n;    p1=2;    p2=-1;        for(m=3; m<=n; m++)    {          for(i=2;i<m;i++)    if(m%i==0)    break;    if(i==m)    {    if(p1==-1)    p1 = i;    else    {    p2=i;    cout<<"{"<<p1<<", "<<p2<<" } ";    p1=-1;    count++;    if(count%2==0)    cout<<endl;    //p2=-1;    }          }else    continue;                }    if(p1!=-1)    {    cout<<"{"<<p2<<", "<<p1<<" } ";    count++;    if(count%2==0)    cout<<endl;    }    system("pause"); }
#include<iostream> using namespace std;
int main() {    int n,i,j,m=2,p1,p2,count=0;    cout<<"Enter n";    cin>>n;    p1=2;    p2=-1;        for(m=3; m<=n; m++)    {          for(i=2;i<m;i++)    if(m%i==0)    break;    if(i==m)    {    if(p1==-1)    p1 = i;    else    {    p2=i;    cout<<"{"<<p1<<", "<<p2<<" } ";    p1=-1;    count++;    if(count%2==0)    cout<<endl;    //p2=-1;    }          }else    continue;                }    if(p1!=-1)    {    cout<<"{"<<p2<<", "<<p1<<" } ";    count++;    if(count%2==0)    cout<<endl;    }    system("pause"); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote