C Program to Check Prime Number

In this program, you will learn to check whether the number entered by the user is a prime number or not. A Prime Number can be divided exactly only by 1, or itself. And it must be a whole number greater than 1.

1

2

3

4

5

6

List of Prime Numbers:

2, 3, 5, 7, 11, 13, 17, 19,

23, 29, 31, 37, 41, 43, 47,

53, 59, 61, 67, 71, 73, 79,

83, 89, 97 and so on.

Example: Program to Check Prime Number

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

#include<stdio.h>

intmain()

{

intnum,i,count=0;

printf("Enter a number: ");

scanf("%d",&num);

for(i=1;i<=num;i++)

{

if(num%i==0)

{

count++;

}

}

if(count==2)

{

printf("%d is a prime number\n",num);

}

else

{

printf("%d is not prime number\n because The number is divisible by ",num);