Professional Documents
Culture Documents
Include
Include
h> void main() { clrscr(); int n,i,np=0;//np is boolean operator (true/false) printf("\n Enter a number :"); scanf("%d",&n); for(i=2;i<=(n-1);i++) /*we know that a number which is divisible by 1 and divisible by itself Is A PRIME NUMBER. So no need to check n divisible by 1 and divisible by itself */ { if(n%i==0) { np=1; break; //come out of for loop } } if(np==1) // in if statement np=1 ,it confirms that number is composite. { printf("Sorry,its composite number %d",n); } else { printf("it is a prime number %d",n); }
OUTPUT: Enter a Number: 12 Sorry its a composite number 12 Enter a number 17 it is a prime number 17