Created
July 26, 2015 14:10
-
-
Save SohanChy/cb16322f130b10048763 to your computer and use it in GitHub Desktop.
Prime Checking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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