Menu driven program of java of Twin prime or not + Twisted prime or not
Very important school project
Answers
Answered by
2
hello,
i can give you the main logical code , since i know c++ & not java.
(sorry for the inconvenience caused)
heres the code:
void main()
{
int a,b=2,c,d=1;
cin>>a>>c;
while(b<a) //to check if a is prime or not
{
if(a%b==0)
break;
b++;
}
while(d<c)
{
if(c%d==0)
break;
c++;
}
if(b==a && c==d) && ((a==c+2)||(a==c-2))
cout<<"twin prime";
else
cout<<"nopes";
}
for twisted prime..
check if the inputted no. is prime or not (apply same logic as above)
then reverse the inputted no. like the palindrome logic & then again check if the reversed no. is prime or not.
if both are prime, it is a twisted prime no else not
HOPE THIS HELPS :)
i can give you the main logical code , since i know c++ & not java.
(sorry for the inconvenience caused)
heres the code:
void main()
{
int a,b=2,c,d=1;
cin>>a>>c;
while(b<a) //to check if a is prime or not
{
if(a%b==0)
break;
b++;
}
while(d<c)
{
if(c%d==0)
break;
c++;
}
if(b==a && c==d) && ((a==c+2)||(a==c-2))
cout<<"twin prime";
else
cout<<"nopes";
}
for twisted prime..
check if the inputted no. is prime or not (apply same logic as above)
then reverse the inputted no. like the palindrome logic & then again check if the reversed no. is prime or not.
if both are prime, it is a twisted prime no else not
HOPE THIS HELPS :)
Similar questions