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.