**The Program in C# Program to Find Next Prime number of Given number is given below:**

```
using System;
namespace NextPrime
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Codeauri Family, enter the number here to find the next prime number: ");
int number = int.Parse(Console.ReadLine());
int nextPrime = FindNextPrime(number);
Console.WriteLine("Okay, the next prime number is: " + nextPrime);
}
static int FindNextPrime(int number)
{
int nextNumber = number + 1;
while (!IsPrime(nextNumber))
{
nextNumber++;
}
return nextNumber;
}
static bool IsPrime(int number)
{
if (number <= 1)
{
return false;
}
for (int i = 2; i <= Math.Sqrt(number); i++)
{
if (number % i == 0)
{
return false;
}
}
return true;
}
}
}
```

## Output:

Hello Codeauri Family, enter the number here to find the next prime number:

7

Okay, the next prime number is: 11

## Pro-Tips**💡**

Here are the step by step execution of above program:

- The first line
`using System;`

imports the System namespace, which provides access to the Console class. - The
`Main`

method is the entry point of the program. It prompts the user to enter a number and reads the input using`Console.ReadLine()`

. - The input is converted to an integer using
`int.Parse()`

and is passed as an argument to the`FindNextPrime`

method. - The
`FindNextPrime`

method takes an integer as input and returns the next prime number after that number. It starts with the number`nextNumber`

as the input number plus one and repeatedly increases it by one until a prime number is found. The`IsPrime`

method is called to check whether the current value of`nextNumber`

is prime or not. - The
`IsPrime`

method takes an integer as input and returns a boolean indicating whether the number is prime or not. It first checks if the number is less than or equal to 1, in which case it returns false. Then, it checks the number for divisibility by all integers from 2 to the square root of the number. If the number is divisible by any of them, it returns false. Otherwise, it returns true. - Finally, the result from the
`FindNextPrime`

method is displayed on the console using`Console.WriteLine`

.

**Learn C-Sharp ↗**

C-sharp covers every topic to learn about C-Sharp thoroughly.

**Learn C Programming ↗**

C-Programming covers every topic to learn about C-Sharp thoroughly.

**Learn C++ Programming↗**

**Learn C++ Programming↗**

C++ covers every topic to learn about C-Sharp thoroughly.