A Prime Number can be divided evenly only by 1, or itself.

A Prime Number must be a whole number greater than 1.

Example:

3 can only be divided evenly by 1 or 3, so it is a prime number.

But 6 can be divided evenly by 1, 2, 3 and 6 so it is NOT a prime number.

Description :

This program accept one Integer from user and checks if it is prime or not. I am using one flag variable and setting that flag to 1 if given number is evenly dividable by any number (except 1 and given number). that’s why my for loop is started with 2 and ended at n/2

Note : There are other efficient ways to write this program. we will discuss them in next posts.

Hi Guys, I am Venkatesh Macha. I am a programmer and an Open Source enthusiast, Presently working as a Software Engineer. Apart from that, I love to explore new technologies and things.