Prime Number is a number which is only divisible by 1 and the number itself i.e., it has no factors other than 1 and itself.
Example 1: 7 is only divisible by 1 and itself only. Hence it is a Prime Number.
Example 2: 4 is divisible by 1 and 2 and 4. Hence it is not a Prime Number.
C
#include <stdio.h>
void main()
{
int n=0,flag=0;
printf("Enter a number: ");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
if(n%i==0)
{
flag++;
}
}
if(flag==2)
{
printf("%d is a Prime Number",n);
}
else
{
printf("%d is not a Prime Number",n);
}
}C