sexy prime pair in C++ (TCS digital 2019) by R4R Team

What is sexy prime?
-A prime pair that have a difference of 6 are called as sexy prime.

Example-
13 and 19 are sexy prime.

program:

#include < iostream>
using namespace std;
class myclass
{
public:
int prime(int n)
{
int i;
for(i=2;i< n-1;i++)
{
if(n%i==0)
{
return 0;
}
}
return 1;
}
};
int main()
{
int x,y,i,count=0;
myclass obj;
cout<<"Enter rangen";
cin>>x>>y;
for(i=x;i<=y;i++)
{
if(obj.prime(i) && obj.prime(i+6))
count++;
}
cout<<"Total sexy prime pair is:n"<< count;
return 0;
}


output-

Enter range
10 40
Total sexy prime pair is:
6




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!