Created
May 28, 2020 16:48
-
-
Save wasit-shafi/85c325bd416dc58d58790c1e9a7d43f3 to your computer and use it in GitHub Desktop.
Prime Number Program
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> | |
#include<math.h> | |
int main() | |
{ | |
int n, i, half, isPrime = 1, square_root; | |
printf("Enter Value of n... "); | |
scanf("%d", &n); | |
square_root = sqrt(n); | |
if(n > 1) | |
{ | |
for(i = 2 ; i <= square_root ; i++) // or for(i = 2 ; i * i <= n ; 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