Skip to content

Instantly share code, notes, and snippets.

@wasit-shafi
Last active May 28, 2020 15:57
Show Gist options
  • Save wasit-shafi/175b9d9b1f36214f85e925298e210ce7 to your computer and use it in GitHub Desktop.
Save wasit-shafi/175b9d9b1f36214f85e925298e210ce7 to your computer and use it in GitHub Desktop.
Prime number Program
#include<stdio.h>
int main()
{
int n, i = 2, half, isPrime = 1;
printf("Enter Value of n... ");
scanf("%d", &n);
half = n / 2;
if(n > 1)
{
for(i = 2 ; i <= half ; i++)
{
if(n % i == 0)
{
isPrime = 0;
break;
}
}
}
else
isPrime = 0;
if(isPrime)
printf("%d is a Prime Number.", n);
else
printf("%d is not a Prime Number.", n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment