Last active
May 28, 2020 15:57
-
-
Save wasit-shafi/175b9d9b1f36214f85e925298e210ce7 to your computer and use it in GitHub Desktop.
Prime number Program
This file contains hidden or 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 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