To determine whether a number is prime or not in a C program, you can use a simple algorithm that checks for divisibility. A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers other than 1 and itself.
Here’s a basic C program to check if a given number is prime or not:
Program :
#include<stdio.h>
#include<conio.h>
main()
{
int i,p,c=0;
printf(“Enter the Number : “);
scanf(“%d”,&p);
for(i=1;i<=p;i++)
{
if(p%i==0)
{
c++;
}
}
if(c==2){
printf(“%d is a Prime Number.”,p);
}
else
{
printf(“%d is not a Prime Number.”,p);
}
return 0;
}