C Program to Check Whether given Number is Prime or Not | detect prime number or not in c Language
Program Description :
What is Prime Number :
- A Prime Number can be divided evenly only by 1, or itself.
- A Prime Number must be a whole number greater than 1.
- 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.
Note : There are other efficient ways to write this program. we will discuss them in next posts.
Program to check number is Prime number or not in C Language :
We will use one flag variable and set that flag to 1 if the given number is evenly dividable by any number (except 1 and the given number). That’s why my for loop is started with 2 and ended at n/2
|C Program to check given Number is Prime or not|