Thursday, May 12, 2016

Check Whether Number Is Prime Or Not.



A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number.


#include <stdio.h>
int main() {
int n, i, x=0;

printf("Enter a No: ");
scanf("%d",&n);

for(i=2;i<=n/2;++i) {
if(n%i==0) {
x=1; break;
}
}

if (x==0)
printf("%d is a prime number.",n);
else
printf("%d is not a prime number.",n);
return 0;

}




Share this

0 Comment to "Check Whether Number Is Prime Or Not."

Post a Comment