Find prime porcupine number.
A prime number is an integer that is divisible by 1 an itself. A porcupine number is a prime number whose last digit is 9 and the next prime number that follows it also ends with the digit 9. For example 139 is a porcupine number because:
- It is prime
- It ends in a 9
- The next prime number after it is 149 which also ends in 9. Note that 140, 141, 142, 143, 144, 145, 146, 147 and 148 are not prime so 149 is the next prime number after 139.
Write a function name isproc() that take two inputs from the user and print the prime porcument number between given ranges.
using System;
namespace porcupine
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("enter starting number ");
int start = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter ending number ");
int end = Convert.ToInt32(Console.ReadLine());
Porcument objporcument = new Porcument();
int answer= objporcument.isproc (start,end);
}
}
}
public class Porcument
{
public int isproc(int start, int end)
{
int s = start, e = end;
int i;
for (i = s; i <= e; i++)
{
int c = 0;
for (int j = 1; j <= e; j++)
{
if (i % j == 0)
{
c++;
}
}
if (c == 2)
{
if (i % 10 == 9)
{
Console.WriteLine(i+ " is an Porcupine Number.");
}
}
}
return 1;
}
}