write a c program that if the given number is prime, and
their rearrangement(permute) of that number is also prime.
Ex: Input is "197" is prime
Output: 791,917,179 is also prime.
Please any one tell me tha code for that
Answer Posted / santosh
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
static boolean permutablePrime(int n)
{
String str=String.valueOf(n);
int len=str.length();
for(int i=0;i<len;i++)
{
String str1=str.substring(0,i);
String str2=str.substring(i,len);
String str3=str2.concat(str1);
//System.out.println(str3);
if(!isPrime(Integer.parseInt(str3)))
{
return false;
}
}
return true;
}
static boolean isPrime(int n)
{
for(int i=2;i<n/2;i++)
{
if(n%2==0)
{
return false;
}
}
return true;
}
public static void main (String[] args)
{
if(isPrime(193))
{
if(permutablePrime(193))
{
System.out.println("permutable prime");
}
else
System.out.println("Not permutable prime");
}
else
{
System.out.println("Not permutable prime");
}
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Can a variable be both const and volatile?
Explain what is wrong with this program statement?
Is int a keyword in c?
What is the translation phases used in c language?
What is strcpy() function?
How do you print only part of a string?
count = 0; for (i = 1;i < = 10; i++);count = count + i; Value of count after execution of the above statements will be a) 0 b) 11 c) 55 d) array
How can I find out the size of a file, prior to reading it in?
What is this pointer in c plus plus?
Where static variables are stored in c?
`write a program to display the recomended action depends on a color of trafic light using nested if statments
When should volatile modifier be used?
my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?
can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......
What is wrong with this initialization?