C Programs / Prime number c program

Program
#include
void main()
{
int i,j,n,k=1;

printf("Enter a number:");
scanf("%d",&n);

for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
k=0;
break;
}
}

if(k==1)
printf("Given number is prime");
else
printf("Given number is not prime");

}
Input Enter a number:5
Output Given number is prime


Home     Back