 # Prime Numbers - How to determine one is a prime number or not?

Hello,

I wanted to make a small consoleapp on C# that organizes prime numbers into an array and prints them out.

My only problem is actually: how do I mathematically and programmatically recognize a prime number to put in that array and then move onto the next number?

Thanks,

• Tech

A prime number cannot be evenly divided like 2, 3, 5, 7, 11, 13, 17, …

So you divide with numbers like 2, 3, and 5, maybe a few others with the modulus operator. If the result is not zero than its prime. ( general answer possibly not complete.)

Depending on how large of a number you are trying to test this page can help ( I described the trial division method).
https://primes.utm.edu/prove/merged.html

List of primes search results to check your method.

2 Likes

a number is prime if it is not divisible by any other number (simple check: n is prime if all numbers below the square root of n (rounded up) don’t evenly divide it)

1 Like

Hey thanks to you guys ! But I’m not sure why you divide by 2, 3 and 5, etc?

Multiples of 2, 3, and 5 cover most numbers. Just the way it is. I take it you haven’t done mush algebra, but that’s ok. the first link gave you many ways to check for primes.

As an exercise start counting and see if the number is evenly divisible by another number. 2 & 3 are prime.

4 is divisible by 2

5 is prime

6 is divisible by 2 and 3

7 is prime

8 is divisible by 2, 8 = 2 x 4, 4 = 2 x 2, so 8 = 2 x 2 x 2 (this is 8 factored. Factoring is the smallest possible numbers multiplied together to make a larger number. In this case 8)

9 = 3 x 3

10 = 2 x 5

11 is prime.

Continue for yourself.

Ok thanks, I have done algebra but 2,3 and 5 don’t cover everything.