Sep18


Printing All Primes using C++ image

The primes numbers are the integers with can only be divided by 1 or by itself.  In other words, a prime number has only two factors which are 1 and the number itself.

The following are some examples:

  • 1 : Have only one factor which is 1 itself. Hence, not a prime
  • 2 : Have 1 and 2 are the only factors. Hence, a prime.
  • 3 : Have 1 and 3 are the only factors. Hence, a prime.
  • 4 : Have 1, 2 and 4 are the factors. Hence, not a prime.
  • 5 : Have 1 and 5 are the only factors. Hence, a prime
  • and so on...

In this program, we will print out the prime numbers up to n which is supplied by the user on runtime.


|0 |206

Be Cool!

If you have any other method in your mind, feel free to share us in the comments below. We will include it with this post along with your credits.

Method 1

Using counting the factors

Ads By Google - Turn it Off

Leave a Comment


gfhdg