To understand better please read the following post first, it will clear your concept of prime number What is prime number and Why 1 is not a prime number?
#include<stdio.h>
int main(){
int n, i,check;
printf("Enter a positive number\n");
scanf("%d",&n);
for(i=2;i<=n/2;i++){
if(n%i==0) {
check = 1;
break;
}
}
if(check==1)
printf("\n%d is not a prime number\n",n);
else
printf("\n%d is a prime number\n",n);
return 0;
}
Logic: The above program takes an integer n to check whether it is prime and use two control variables...
|