public static void Main()
int inputNumber = 0 , nextPrimenumber = 0;
inputNumber = Convert.ToInt32(Console.ReadLine());
nextPrimenumber = fn_nextPrimenumber(inputNumber);
Console.WriteLine("\nEnter valid integer.");
Console.WriteLine("\nNext Prime numer of {0} is : {1} " , inputNumber ,nextPrimenumber);
public static int fn_nextPrimenumber(int number)
int nextPrimenumber , divisibleBy = 2 , isPrime = 0;
bool isPrimefound = false ;
nextPrimenumber = number;
while (isPrimefound == false && number != 1 && number != 2)
while (divisibleBy <= nextPrimenumber - 1)
if (nextPrimenumber % divisibleBy == 0)
if (nextPrimenumber % divisibleBy != 0)
if (isPrime == nextPrimenumber - 2)
nextPrimenumber = nextPrimenumber + 1 ;
return nextPrimenumber - 1;