C++ program to display prime numbers between two intervals

C++ program to display prime numbers between two intervals
A Prime Number is a whole number that cannot be made by multiplying other whole numbers

A prime number is a whole number that is greater than one and the only factors of a prime number should be one and itself. Some of the first prime numbers are 2, 3, 5, 7, 11, 13 ,17 etc.

There can be many prime numbers between two intervals. For example, the prime numbers between the intervals 5 and 15 are 5, 7, 11 and  13

 

Some facts:

The only even prime number is 2. All other even numbers can be divided by 2.
If the sum of a number's digits is a multiple of 3, that number can be divided by 3.
No prime number greater than 5 ends in a 5. Any number greater than 5 that ends in a 5 can be divided by 5.
Zero and 1 are not considered prime numbers.
Except for 0 and 1, a number is either a prime number or a composite number. A composite number is defined as any number, greater than 1, that is not prime.

To prove whether a number is a prime number, first try dividing it by 2, and see if you get a whole number. If you do, it can't be a prime number. If you don't get a whole number, next try dividing it by prime numbers: 3, 5, 7, 11 (9 is divisible by 3) and so on, always dividing by a prime number

The program to find and display the prime numbers between two intervals is given as follows.

 

Example: Display Prime Numbers Between two Intervals


Output

Enter two numbers(intervals): 5
30
Prime numbers between 5 and 30 are: 5 7 11 13 17 19 23 29

Post a Comment

Previous Post Next Post