The number which is only divisible by one and itself is called prime number.For example 13 is a prime number which is only divisible by 1 and 13.There are various way to find prime number but here we provide an easy C program to check number is prime or not .
C program to check number is prime or not.
#include<stdio.h>
int main()
{
int num, i, count = 0;
printf("Enter a number:");
scanf("%d", &num);
for (i = 2; i <= num / 2; i++)
{
if (num % i == 0)
{
count++;
break; // to exit from this block
}
}
if (count == 0)
printf("%d is a prime number", num);
else
printf("%d is not a prime number", num)
return 0;
}
}
output:
Enter a number: 23
23 is a prime number