In this article, you will learn to print all the prime numbers between a given interval.
What is a Prime number?
A prime number is a whole number greater than 1 whose only factors are 1 and itself. A factor is a whole number that can be divided evenly into another number.
The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, and 29.
Step to create these programs:
- First, we take the first number as 1
- Then we take the second number from the user
- Then we iterate the for loop from first to last+1
- Then we check the number is greater than 1
- Then we iterate again for the second loop from 2 to num
- Then we check the num, divide the num from the for loop and the check is equal to zero
- Otherwise, print num
Enter the number: 12 2 3 5 7 11