Circular prime number: A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will be prime. The number, 379, is a circular prime because all rotations of the digits: 793, 937, and 379, are themselves prime numbers.
class Program
{
static void Main(string[] args)
{
int num, temp = 0;
Console.WriteLine("Enter a Number : ");
num = int.Parse(Console.ReadLine());
temp = prime(num);
if (temp == 1)
{
temp = Curculerprime(num);
Console.WriteLine("Number is circular prime ");
}
else
Console.WriteLine("Number is not circular prime ");
Console.ReadLine();
}
private static int prime(int no)
{
for (int i = 2; i <= no / 2; i++)
{
if ((no % i) == 0)
{
Console.WriteLine("Not a prime ");
return 0;
}
break;
}
return 1;
}
private static int Curculerprime(int num)
{
int N = num;
int temp = 0, i = 0;
int rem, tp = 0;
while ((N != 0))
{
N = N / 10;
tp++;
}
N = num;
while (i < tp)
{
rem = N % 10;
N = N / 10;
N = N * 10 + rem;
temp = prime(N);
if (temp == 0)
{
Console.WriteLine("Not a circular prime ");
break;
}
else
i++;
}
return 1;
}
}
No comments:
Post a Comment