A number which is divisible by itself (or we can say number which is divisible by 1 and itself), note that: 1 is not a prime number, they are start from 2.
In this program, we are writing a program that will print only prime numbers from 2 to 30.
For example:
2 is prime number.
3 is prime number.
4 is not prime number because it can be dividing by 2.
5 is again a prime number.
Consider the program:
Output
Here, we used a loop which is running from 2 to 30 and the inner loop is running from 2 to half of the number.
If number is divisible by any number from 2 to half of the number, it will not be a prime number and loop is breaking here.