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
Answers were Sorted based on User's Feedback
Answer / sowmya
hello Sir,
If you dont mind, could you exlain that above code
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / 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 |
Answer / chaskar tejal
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("197 is prime");
if a%2 || a%3||a%5||a%7
getch();
}
| Is This Answer Correct ? | 1 Yes | 5 No |
Expand the following LKB BKL FFG
Can we increase size of array in c?
find a number whether it is even or odd without using any control structures and relational operators?
22 Answers Microsoft, Shashank Private Limited,
#include<stdio.h> int main() { int i=2; int j=++i + ++i + i++; printf("%d\n",i); printf("%d\n",j); }
Explain how do you generate random numbers in c?
pointer_variable=(typecasting datatype*)malloc(sizeof(datatype)); This is the syntax for malloc?Please explain this,how it work with an example?
2 Answers eClerx, Excel, kenexa,
What is a structure in c language. how to initialise a structure in c?
Why do we use int main instead of void main in c?
What is a class c rental property?
LOGIC OF Bodmas?
Write a program for the following series: 1*3*5-2*4*6+3*5*7-4*6*8+.................up to nterms
how to use enum datatype?Please explain me?