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

The number of bytes of storage occupied by short, int and long are a) 2, 2 and 4 b) 2, 4 and 4 c) 4, 4 and 4 d) none

0 Answers  


main() { int a,b; printf("%d,%d",scanf("%d%d",&a,&b)); } => do u mean above program's output... =>output will be:2,whatever you enter value for b. =>because scanf is a library fn which will return how many arguements it processes, and second value you are right mr.Satya but i found my self unable to understand that for the first time scanf returns the no of successful matches but how for the second time it returns the value of 'b'.while a function should return the same 'r' value every time.

1 Answers   Cisco,


write a fuction for accepting and replacing lowercase letter to'Z' with out using inline function.

5 Answers   Temenos,


What are the usage of pointer in c?

0 Answers  


what is meant by the "equivalence of pointers and arrays" in C?

3 Answers   Satyam,






2.Given the short c program that follows a. make a list of the memory variables in this program b.which lines of code contain operations that change the contents of memory? what are those operations? Void main( void) { Double base; Double height; Double area; Printf(“enter base and height of triangle :”); Scanf(“%lg”, &base); Scanf(“%lg”, &height); Area=base*height/2.0; Printf(“the area of the triangle is %g \n”,area); }

1 Answers   Wipro,


What are the types of data types and explain?

0 Answers  


how to find the kth smallest element in the given list of array elemnts.

8 Answers   Silicon,


Why static variable is used in c?

0 Answers  


A program to write a number of letters and numbers, such as counting and display

0 Answers  


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

1 Answers   Mind Tree,


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

0 Answers  


Categories