Check if a number is prime number with C# programming language


On the post we going to write a simple program to check either the number given is prime number or not. The number will be read on Console.

As we already familiar with in mathematics, prime number is any positive integer number that cannot be divided by another number except 1 and itself. to check either given number is a prime number not using C# program, just copy a paste these below on your development environment i.e visual studio.

Console.WriteLine("Hello World!");

Like Our Facebook page

Console.WriteLine("Enter as positve number: " );

int num = int.Parse(Console.ReadLine());

int divider = 2;

READ ALSO  In honor of a supervisory councillor from Isu LGA who was shot dead yesterday, while protesting their illegal suspension by Governor Emeka Ihedioha

int maxDivider = (int)Math.Sqrt(num);

bool prime = true;

while (prime && (divider <= maxDivider))


if (num % divider == 0)


prime = false;




Console.WriteLine("prime? " + prime);

When run these code above, it will prompt us to enter positive number on the console window shown below

Now as we enter positive number  (37) on the above page and heat enter, it will show  us prime number is  true.

READ ALSO  Fani Kayode recounts unholy activities in the North

now to either the prime is false, enter 34, a page show will display telling us that prime number is false

As we can see on the above page, it show that prime number is false, while because we enter 34 which is not a prime number.

That is all for these tutorial we will bring video that explain everything teach later.

READ ALSO  Pure water sellers at the road side need more help than fake beggars

Thanks for reading, have any question or comment drop on our comment section below.

Want To Support Us By Donating Click Here


Article Rating


Stories You May find Interesting

Notify of
Inline Feedbacks
View all comments