Skip to content

Instantly share code, notes, and snippets.

@SohanChy
Created July 26, 2015 14:10
Show Gist options
  • Save SohanChy/cb16322f130b10048763 to your computer and use it in GitHub Desktop.
Save SohanChy/cb16322f130b10048763 to your computer and use it in GitHub Desktop.
Prime Checking
#include <stdio.h>
int main()
{
int x,isprime=1;
scanf("%d",&x);
if(x==1 || x==2)
{
printf("Prime Number %d",x);
isprime=0;
}
else if(x%2==0)
{
printf("NOT prime %d",x);
isprime=0;
}
else if(x>2)
{
int div;
for(div=3;div<x;div=div+2)
{
if (x%div!=0)
{isprime=1;}
else {
isprime=0;
printf("Not Prime %d",x);
break;
}
}
}
if(isprime==1){printf("%d is PRIME",x);}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment