Develop a C# function to check whether a given number n is a prime number. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Develop a C# function to check whether a given number n is a prime number. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Prime Number Checker in C#
Below is a simple implementation of a prime number checker in C#,
Example-
In the above example-
number.IsPrimefunction to check if the input number is prime.IsPrimefunction checks if the number is less than 2 and returns false if it is, because 0 and 1 are not prime numbers.Output- 1
Output- 2
This function must carefully check whether the given quantity is prime or not.
Also, Read: Fibonacci Sequence