Showing posts with label Prime Numbers. Show all posts
Showing posts with label Prime Numbers. Show all posts

Check If A Number Is A Prime Number


C++ program to check if a number is a prime number


Problem:
Write a C++ program which checks if a number is a prime number or not?
A prime number is any natural number greater than 1 with no other positive factors other than 1 and itself. 

Let's take 5 as an example:
1 and 5 (the number itself) can evenly divide 5 so they are factors of 5.
2, 3, 4 are cannot evenly divide 5 so they are not factors of 5.
Therefore, 5 is a Prime Number.
The program below shows a number is asked and it is evaluated if a prime number or not.


Prime Numbers Between 1-1000

C++ program to find prime numbers between 1 to 1000


Problem:
Write a C++ program which prints all the prime numbers from 1-1000. 

Prime numbers are numbers greater than 1 and which has 1 and the number itself as positive factors or divisors. It doesn't have a positive factor or divisors other than 1 and the number itself.

Let's take 5 for example:
1 and 5 (the number itself) can evenly divide 5 so they are factors of 5.
2, 3, 4 are cannot evenly divide 5 so they are not factors of 5.
Therefore, 5 is a Prime Number.

This is a program which shows the Prime Numbers from 1-1000.