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



write a c program that if the given number is prime, and their rearrangement(permute) of that numb..

Answer / sowmya

hello Sir,

If you dont mind, could you exlain that above code

Is This Answer Correct ?    0 Yes 0 No

write a c program that if the given number is prime, and their rearrangement(permute) of that numb..

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

write a c program that if the given number is prime, and their rearrangement(permute) of that numb..

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

Post New Answer

More C Interview Questions

How can I find out if there are characters available for reading?

0 Answers  


Why is main function so important?

0 Answers  


what is the other ways to find a logic to print whether a number is an even or odd wit out using % symbol??????? i know three different ways to print it. so i need any other different logic>>>>>

5 Answers   TCS,


which of the following go out of the loopo if expn 2 becoming false a.while(expn 1){...if(expn 2)continue;} b.while(!expn 1){if(expn 2)continue;...} c.do{..if(expn 1)continue;..}while(expn 2); d.while(!expn 2){if(expn 1)continue;..}

4 Answers   TCS,


x=y=z=1 z=++x||++y&&++z Printf("%%%d";xyz) what is the values of x,y and z?????

3 Answers  






If one class contains another class as a member, in what order are the two class constructors called a) Constructor for the member class is called first b) Constructor for the member class is called second c) Only one of the constructors is called d) all of the above

0 Answers  


What is a buffer in c?

0 Answers  


What are the 3 types of structures?

0 Answers  


#define d 10+10 main() { printf("%d",d*d); }

6 Answers  


Why main function is special give two reasons?

0 Answers  


Explain how do you determine the length of a string value that was stored in a variable?

0 Answers  


printf("%d",(printf("Hello")); What it returns?

32 Answers   TCS,


Categories