Skip to content

Instantly share code, notes, and snippets.

@enile8
Created July 28, 2012 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enile8/3191460 to your computer and use it in GitHub Desktop.
Save enile8/3191460 to your computer and use it in GitHub Desktop.
Is it a Prime Number?
#include <stdio.h>
int main(void) {
int n,
lcv,
flag; /* flag starts as 1 and becomes 0 if it's determined that the
number is not prime */
printf("Enter value of the number\n");
scanf("%d", &n);
for (lcv=2, flag=1; lcv <= (n / 2); lcv++) {
if ((n % lcv) == 0) {
if (lcv == 2)
printf("The factors of %d are:\n", n);
printf("%d ", lcv);
flag = 0;
}
}
printf("\n");
if (flag == 1)
printf("%d is a prime number\n", n);
else
printf("%d is not a prime number\n", n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment